Reputation: 41
Since I do not have Perl on my system, I need to rewrite the Perl script using a shell script. Perl script reads through the file which has username and encrypted password. Perl script then compares the user entered username and encrypts user entered password with the contents of the file read.
Perl uses the crypt
function for encrypting.
crypt(password, salt)
where salt = "$1$" +storeRandomNumber+ "$xxxxxxxxxxxxxxxxxxxxxx";
but in case of shell script I am using
echo $password | openssl enc -aes-128-cbc -a -d -salt -pass pass:wtf
There is mismatch in encrypted password in Perl and shell. Please help me in implementing matching crypt()
function in shell program. FYI, I cannot modify the password file.
Upvotes: 0
Views: 153
Reputation: 3310
Openssl's "enc -aes" is used to symetrically encrypt a string, i.e. the result could later be decrypted again.
Perl's crypt() is used to "hash" a password, like a cross sum or checksum. You cannot get the original value from the result. You can check if a user's input yields to the same "checksum" though to check if it's (most probably) the correct password.
Long story short, use this command:
echo -n "secret" | openssl passwd -stdin -1 -salt 12345678
$1$12345678$hj0uLpdidjPhbMMZeno8X/
Use "-n" with echo or you will have a Newline (\n) after the password. In a script, rather use "openssl -in" to read from a file.
Upvotes: 1