RE: MySQLPHP decrypt(password)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Password and MD$ return different values. They are not compatible. Since both are one way encryptions, you can not retrive the orginal value


From: "moses Woldeselassie" <mmoses@xxxxxxxxxxx>
To: bastien_k@xxxxxxxxxxx, php-db@xxxxxxxxxxxxx
Subject: RE:  MySQLPHP decrypt(password)
Date: Mon, 28 Feb 2005 16:44:56 +0000


thank you Bastien

I do have a login and registration php sript, which work fine. the problem is I am using password(passwd) to registrat the user, and i did change md5 into password() but how do i get the password that a user has registrated in the first time?



other problem:

i did try to use the sending email using the following:

select passwd from users where username=$mid and email = $email

but it doesn't work. If i put * instead of passwd it works fine.
select * from users where username=$mid and email=$email

what is the problem?

I didn't get it, a user should easliy login using the new password, which was changed using change_password().



kind regards
m




&gt;From: &quot;Bastien Koert&quot; &lt;bastien_k@xxxxxxxxxxx&gt;
&gt;To: mmoses@xxxxxxxxxxx
&gt;Subject: RE: MySQLPHP decrypt(password)
&gt;Date: Mon, 28 Feb 2005 09:31:20 -0500
&gt;
&gt;There needs to be a separate login page...The previous page was simply to change the password...
&gt;
&gt;here is my login function...
&gt;
&gt;//---------------------------------------------------------------------------------------
&gt;// login function
&gt;//---------------------------------------------------------------------------------------
&gt;function login()
&gt;{
&gt; global $err_msg;
&gt; $errors = array();
&gt;
&gt; if ((empty ($_POST['lg_name']))&amp;&amp;(!eregi(&quot;[[:alnum:]]&quot;,$_POST['lg_name']))){
&gt; $errors[] = &quot;&lt;font color=red&gt;You didn't enter a correct login name.&lt;/font&gt;&quot;;}
&gt; if ((empty ($_POST['lg_pw']))&amp;&amp;(!eregi(&quot;[[:alnum:]]&quot;,$_POST['lg_pw']))){
&gt; $errors[] = &quot;&lt;font color=red&gt;You didn't enter a password.&lt;/font&gt;&quot;;}
&gt;
&gt; if (count($errors) &gt; 0) {
&gt;
&gt; for ($i = 0; $i &lt; $nerrors; $i++){
&gt; $err_msg .= $errors[$i].&quot;&lt;br /&gt;&quot;;
&gt; }
&gt; show_form();
&gt; exit();
&gt; }//end if
&gt;
&gt; $lg_name = $_POST['lg_name'];
&gt; $lg_pw = $_POST['lg_pw'];
&gt;
&gt; $new_select = &quot;select cust_lg, cust_pw, temp_pass from cust_info where cust_lg = '$lg_name' and cust_pw = '$lg_pw'&quot;;
&gt; $result = connect($new_select);
&gt; $num_result = mysql_num_rows ($result);
&gt;
&gt; if ($num_result == 1) {
&gt;
&gt; //if the temp_password value is set to 1 then have the user change the password.
&gt; $row = mysql_fetch_array($result);
&gt; if ($row['temp_pass']==1){
&gt; header(&quot;location:change_pass.php&quot;);
&gt; die();
&gt; }//end if
&gt;
&gt; setcookie('last_time', date(&quot;Ymd-his&quot;),time()+60*60*24*30,'/');
&gt; echo &quot;here&quot;;
&gt; header(&quot;location:/login_unit/brokerpanel.htm&quot;);
&gt; exit();
&gt; }else{
&gt; $err_msg = &quot;&lt;font color=red&gt;No match found! If you have forgotten your password, please click the link at the right.&lt;/font&quot;;
&gt; show_form();
&gt; exit();
&gt; }
&gt;}//end functon
&gt;
&gt;?&gt;
&gt;
&gt;bastien
&gt;
&gt; &gt;From: &quot;moses Woldeselassie&quot; &lt;mmoses@xxxxxxxxxxx&gt;
&gt; &gt;To: bastien_k@xxxxxxxxxxx, php-db@xxxxxxxxxxxxx
&gt; &gt;Subject: RE: MySQLPHP decrypt(password)
&gt; &gt;Date: Mon, 28 Feb 2005 11:16:23 +0000
&gt; &gt;
&gt; &gt;Thank you Bastien
&gt; &gt;
&gt; &gt;It works fine, but i do have a problem with login. MySQL does not allowed the user to login.
&gt; &gt;
&gt; &gt;
&gt; &gt;I did try to use sending email without using the change_password(), but it is sending different password each time:
&gt; &gt;
&gt; &gt;1. Why is it sending different password for one user?
&gt; &gt;2. How could I get a user password without changing a user password?
&gt; &gt;
&gt; &gt;
&gt; &gt;
&gt; &gt;
&gt; &gt;kind regards
&gt; &gt;m
&gt; &gt;
&gt; &gt;
&gt; &gt;
&gt; &gt;
&gt; &gt;
&gt; &gt;
&gt; &gt;&amp;gt;From: &amp;quot;Bastien Koert&amp;quot; &amp;lt;bastien_k@xxxxxxxxxxx&amp;gt;
&gt; &gt;&amp;gt;To: mmoses@xxxxxxxxxxx, php-db@xxxxxxxxxxxxx
&gt; &gt;&amp;gt;Subject: RE: MySQLPHP decrypt(password)
&gt; &gt;&amp;gt;Date: Fri, 25 Feb 2005 14:04:30 -0500
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt;You can't. Its an MD5 hash, not an encryption...I reset the password to a random one, and email it to the user, also flag the account to force them to change the password upon login...
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt;[code]
&gt; &gt;&amp;gt;function mail_password()
&gt; &gt;&amp;gt;{
&gt; &gt;&amp;gt; global $err_msg;
&gt; &gt;&amp;gt; //get the variables from the form
&gt; &gt;&amp;gt; if ((isset($_POST['email']))&amp;amp;&amp;amp;(isset($_POST['lg_name']))){
&gt; &gt;&amp;gt; $email = $_POST['email'];
&gt; &gt;&amp;gt; $mid = $_POST['lg_name'];
&gt; &gt;&amp;gt; $date_cookie = $_COOKIE['last_time'];
&gt; &gt;&amp;gt; }else{
&gt; &gt;&amp;gt; $err_msg = &amp;quot;&amp;lt;b&amp;gt;Please enter both your email address and your username. Thank you.&amp;lt;/b&amp;gt;&amp;quot;;
&gt; &gt;&amp;gt; show_form();
&gt; &gt;&amp;gt; die();
&gt; &gt;&amp;gt; }//end if
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt; //create the sql and run the query
&gt; &gt;&amp;gt; $sql = &amp;quot;SELECT * FROM users WHERE user_email='$email' and user_name = '$mid'&amp;quot;;
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt; $result = connect($sql);
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt; //check the query results
&gt; &gt;&amp;gt; if (mysql_num_rows($result)!=1){
&gt; &gt;&amp;gt; $err_msg = &amp;quot;&amp;lt;font color=red&amp;gt;No results found. Please re-enter your username and email address to try again.&amp;lt;/font&amp;gt;&amp;quot;;
&gt; &gt;&amp;gt; show_form();
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt; }else{
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt; $row = mysql_fetch_array($result);
&gt; &gt;&amp;gt; $email2 = $row['cust_email'];
&gt; &gt;&amp;gt; $pass = $row['cust_pw'];
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt; //call the change password function and pass it the information related to the record to create the temp password
&gt; &gt;&amp;gt; $new_pass = change_password($mid, $pass);
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt; $sendto = $email2;
&gt; &gt;&amp;gt; $from = &amp;quot;WebMaster &amp;lt;webmaster@xxxxxxxxxxxxxxxxxxx&amp;gt;&amp;quot;;
&gt; &gt;&amp;gt; $subject = &amp;quot;Forgotten Password&amp;quot;;
&gt; &gt;&amp;gt; $message = &amp;quot;Dear $email2,
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt; Your password is $new_pass.
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt; Regards,
&gt; &gt;&amp;gt; Webmaster&amp;quot;;
&gt; &gt;&amp;gt; echo $message;
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt; $headers = &amp;quot;MIME-Version: 1.0\n&amp;quot;;
&gt; &gt;&amp;gt; $headers .= &amp;quot;Content-type: text/plain; charset=iso-8859-1\n&amp;quot;;
&gt; &gt;&amp;gt; $headers .= &amp;quot;X-Priority: 3\n&amp;quot;;
&gt; &gt;&amp;gt; $headers .= &amp;quot;X-MSMail-Priority: Normal\n&amp;quot;;
&gt; &gt;&amp;gt; $headers .= &amp;quot;X-Mailer: php\n&amp;quot;;
&gt; &gt;&amp;gt; $headers .= &amp;quot;From: \&amp;quot;&amp;quot;.$from.&amp;quot;\&amp;quot; &amp;lt;&amp;quot;.$from.&amp;quot;&amp;gt;\n&amp;quot;;
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt; if (!mail($sendto, $subject, $message, $headers)){
&gt; &gt;&amp;gt; echo &amp;quot;Mail failed to send&amp;quot;;
&gt; &gt;&amp;gt; }else{
&gt; &gt;&amp;gt; header(&amp;quot;location:confirm1.htm&amp;quot;);
&gt; &gt;&amp;gt; }//end if
&gt; &gt;&amp;gt; }//end if
&gt; &gt;&amp;gt;}//end function
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt;//---------------------------------------------------------------------------------------
&gt; &gt;&amp;gt;// change password function
&gt; &gt;&amp;gt;//---------------------------------------------------------------------------------------
&gt; &gt;&amp;gt;function change_password($id, $password)
&gt; &gt;&amp;gt;{
&gt; &gt;&amp;gt; //generate a random password
&gt; &gt;&amp;gt; $pass = &amp;quot;&amp;quot;;
&gt; &gt;&amp;gt; $salt = &amp;quot;abchefghjkmnpqrstuvwxyz0123456789&amp;quot;;
&gt; &gt;&amp;gt; srand((double)microtime()*1000000);
&gt; &gt;&amp;gt; $i = 0;
&gt; &gt;&amp;gt; while ($i &amp;lt;= 7) {
&gt; &gt;&amp;gt; $num = rand() % 33;
&gt; &gt;&amp;gt; $tmp = substr($salt, $num, 1);
&gt; &gt;&amp;gt; $pass = $pass . $tmp;
&gt; &gt;&amp;gt; $i++;
&gt; &gt;&amp;gt; }
&gt; &gt;&amp;gt; //change the password in the db
&gt; &gt;&amp;gt; $sql = &amp;quot;update cust_info set cust_pw ='&amp;quot;.md5($pass).&amp;quot;', temp_pass = 1 where cust_lg = '$id' and cust_pw = '$password'&amp;quot;;
&gt; &gt;&amp;gt; $result = connect($sql);
&gt; &gt;&amp;gt; if ($result){
&gt; &gt;&amp;gt; return $pass;
&gt; &gt;&amp;gt; }else{
&gt; &gt;&amp;gt; change_password($id, $password);
&gt; &gt;&amp;gt; }
&gt; &gt;&amp;gt;}//end function
&gt; &gt;&amp;gt;[/code]
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt;bastien
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt;
&gt; &gt;&amp;gt; &amp;gt;From: &amp;quot;moses Woldeselassie&amp;quot; &amp;lt;mmoses@xxxxxxxxxxx&amp;gt;
&gt; &gt;&amp;gt; &amp;gt;To: php-db@xxxxxxxxxxxxx
&gt; &gt;&amp;gt; &amp;gt;Subject: MySQLPHP decrypt(password)
&gt; &gt;&amp;gt; &amp;gt;Date: Fri, 25 Feb 2005 10:20:55 +0000
&gt; &gt;&amp;gt; &amp;gt;
&gt; &gt;&amp;gt; &amp;gt;hi all
&gt; &gt;&amp;gt; &amp;gt;
&gt; &gt;&amp;gt; &amp;gt;I am using password() to crypt a user password online. but how do i decrypt a user password, when user forgot his/her password?
&gt; &gt;&amp;gt; &amp;gt;
&gt; &gt;&amp;gt; &amp;gt;
&gt; &gt;&amp;gt; &amp;gt;kind regards
&gt; &gt;&amp;gt; &amp;gt;m
&gt; &gt;&amp;gt; &amp;gt;
&gt; &gt;&amp;gt; &amp;gt;--
&gt; &gt;&amp;gt; &amp;gt;PHP Database Mailing List (http://www.php.net/)
&gt; &gt;&amp;gt; &amp;gt;To unsubscribe, visit: http://www.php.net/unsub.php
&gt; &gt;&amp;gt; &amp;gt;
&gt; &gt;&amp;gt;
&gt; &gt;
&gt;



-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux