php equivalent for mysql "password"

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

DoppyNL

php equivalent for mysql "password"

Postby 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: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: php equivalent for mysql "password"

Postby 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

Postby 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: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: php equivalent for mysql "password"

Postby 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

Postby 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

curryfy
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Nov 27, 2012 1:08 pm

Re: php equivalent for mysql "password"

Postby curryfy » Tue Nov 27, 2012 1:11 pm

You can also use this code :

Code: Select all

function password($str) { return '*'.strtoupper(sha1(pack('H*',sha1($str)))); }


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 3 guests