php equivalent for mysql "password"

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
DoppyNL

php equivalent for mysql "password"

Post by DoppyNL » Mon Aug 19, 2002 1:04 am

Is there a php-equivalent function for the mysql function "password" ??

This way I don't have to run a mysql-query to encrypt a password.

Greetz Daan

User avatar
WiZARD
Moderator
Moderator
Posts: 1256
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: php equivalent for mysql "password"

Post by WiZARD » Mon Aug 19, 2002 6:36 am

dvdbinternet wrote:Is there a php-equivalent function for the mysql function "password" ??

This way I don't have to run a mysql-query to encrypt a password.

Greetz Daan

Hi!
Yes you can find info about encrypting passwod at http://www.mysql.com/documentation/mysql/full/

DoppyNL

Post by DoppyNL » Mon Aug 19, 2002 6:39 am

from a newsgroup:

This function will do the same thing:

Code: Select all

function mysql_password($password)
 {
     $nr = 1345345333;
     $add = 7;
     $nr2 = 0x12345671;
     for ($i = 0; $i < strlen($password); $i++)
     {
         if ($password[$i] == ' ' || $password[$i] == '\t')
             continue;
 
         $tmp = ord($password[$i]);
         $nr ^= (($nr & 63)+$add)*$tmp + ($nr << 8);
         $nr2 += ($nr2 << 8) ^ $nr;
         $add += $tmp;
     }
     $h1 = $nr  & (1<<31) - 1;
     $h2 = $nr2 & (1<<31) - 1;
 
     return sprintf("%08lx%08lx", $h1, $h2);
 }


Greetz Daan

User avatar
WiZARD
Moderator
Moderator
Posts: 1256
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: php equivalent for mysql "password"

Post by WiZARD » Mon Aug 19, 2002 6:48 am

dvdbinternet wrote:Is there a php-equivalent function for the mysql function "password" ??

This way I don't have to run a mysql-query to encrypt a password.

Greetz Daan

Wait a minutes, you need encrypt a password and insert to MySQL db?

DoppyNL

Post by DoppyNL » Mon Aug 19, 2002 6:52 am

yep, but I want to encrypt the password before the query is build because of the dynamic structure in my pages.
It was easyer for me to encrypt it first and the send it to the database then to adjust the code for building the query.

Greetz Daan

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests