Home > Uncategorized > MySQL ENCRYPT() == PHP crypt + salt

MySQL ENCRYPT() == PHP crypt + salt

PHP
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]
Join the forum discussion on this post - (1) Posts
Share and Enjoy:
  • Twitter
  • Digg
  • Facebook
  • MySpace
  • Google Bookmarks
  • email
  • del.icio.us
  • LinkedIn
  • StumbleUpon
  • Reddit
  • Yahoo! Buzz
  • Suggest to Techmeme via Twitter
  • Twitthis
Categories: Uncategorized Tags:

Powered by WP Robot