I have a script that asks for the user's password and I want to check if the given password is wrong or not.#A little fragment of my scriptread -sp 'Your password: ' password;if [[ $password -ne WHAT GOES HERE? ]]; then    MORE CODE HEREelse    MORE CODE HEREfi
Check user's password with a shell script
linux;scripting;password
There's no fully portable way to check the user's password. This requires a privileged executable, so this isn't something you can whip up from scratch. PAM, which is used on most non-embedded Linux systems as well as many embedded systems and most other Unix variants, comes with a setuid binary but it doesn't have a direct shell interface, you need to go via the PAM stack.You can use a PAM binding in Perl, Python or Ruby.You can install one of several checkpassword implementations.If the user is allowed to run sudo for anything, then sudo -kv will prompt for authentication (unless this has been disabled in the sudo configuration). But that doesn't work if there's no sudoers rule concerning the user.You can run su. This works on most implementations. This is probably the best bet in your case.if su -c true $USER; then  echo Correct passwordfi