MySQL ENCRYPT() == PHP crypt + salt

- Image via Wikipedia
I was working on a web interface to ease the addition of users/domains, aliases and forwards to my Postfix-sasl-smtp_auth mysql setup. I knew that the passwords were using mysql’s encypt() function, and this was the only way I was able to get postfix to authenticate and play nice with encrypted passwords. On the PHP side I was using PDO and I was looking for a way to encrypt the passwords using php, that would still allow users to authenticate when sending mail.
$salt = substr($_POST['postfix_mailbox_password'], 0, 2);
$password = crypt($_POST['postfix_mailbox_password'], $salt);
After much trial and error I finally had a working solution, by taking the first two characters of the password and using them as the salt value, I could then use PHP’s crypt() with the salt value to encrypt the password.
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_c.png?x-id=c128ca3e-cfde-4ab1-a79b-2e4a4fabe9cf)






Recent Comments