Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

php equivalent for mysql "password"

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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
DoppyNL
 

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/
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

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
DoppyNL
 

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?
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

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
DoppyNL
 

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)))); }
curryfy
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Nov 27, 2012 1:08 pm


Return to PHP coding => General

Who is online

Users browsing this forum: ScroogeMcDuck and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.