Jump to content

help with password function


asherinho

Recommended Posts

Hi! I am having a problem with password function is not working,here is the code

 

$db=mysql_connect("localhost","root","");

mysql_select_db("ppra_flis",$db);

$result=mysql_query("select * from login where uname='".$uname."' and pass=password('".$pass."')");

 

 

the variable $pass is not converted into encrypted form

Link to comment
https://forums.phpfreaks.com/topic/114229-help-with-password-function/
Share on other sites

What is the code for the password function? If I were you, I would just use:

 

<?php
  $password = 'mycoolPA55w0rd';
  
  $con = mysql_connect(...);
  mysql_select_db(...);
  $query = sprintf("SELECT * FROM `login` WHERE `uname` = '%s' AND `pass` = '%s' LIMIT 1", 
    sha1($password)); // Need code for password()!!
  $result = mysql_query($query) or trigger_error(mysql_error());
?>

Hi,

 

Your using the sql password function in the query, so the value of $pass will not change from what it is set to originally.

 

As shown by wolphie, if you want to change the value of $pass you will need to do something like

 

$pass = sha1($pass);

 

or

 

$pass = md5($pass);

If you want to be extra secure, use these functions, but change the salt(make sure they're the same in each function):

 


function encrypt_password($password){
     
      $salt = "justarandomword";
      $encrypted_password = sha1($salt.$password);
      return $encrypted_password;
}

 

And to compare password attempt:

 

function compare_passwords($password_attempt, $actual_password){
     
      $salt = "justarandomword";
      $password_attempt = sha1($salt.$password_attempt);

      if($password_attempt == $actual_password){
        return true;
      }

      else{
        return false;
      }
      
}

 

Forgive any small bugs/errors.

It worked but there is a database problem.The convertion of md5() and sha1() in database is different from the one in php page thus there is no match.

 

example: in database the md5() convert the word 'user' to ee11cbb1 while the php page converts it to ee11cbb19052e40b07aac0ca060c23ee 

 

here are the codes

php codes: $passwod=md5($pass); $result=mysql_query("select * from login where uname='".$uname."' and pass='".$passwod."'");

 

database query: insert into login(uname,pass,status) values('user',md5('user'),'user')

It worked but there is a database problem.The convertion of md5() and sha1() in database is different from the one in php page thus there is no match.

 

example: in database the md5() convert the word 'user' to ee11cbb1 while the php page converts it to ee11cbb19052e40b07aac0ca060c23ee 

 

here are the codes

php codes: $passwod=md5($pass); $result=mysql_query("select * from login where uname='".$uname."' and pass='".$passwod."'");

 

database query: insert into login(uname,pass,status) values('user',md5('user'),'user')

 

sha1 and md5 are different from one another... if that's what you're talking about.

 

Use only one of them in your system to avoid confusion.

 

Secondly, make sure there are no length restrictions on your password column as this can essentially cut the password's length, which in turn makes it absolutely useless. Use a text column for it.

 

Thirdly, is $passwod not supposed to be $password?

 

This...

$result=mysql_query("select * from login where uname='".$uname."' and pass='".$passwod."'");

 

Can be done like so:

$result=mysql_query("select * from login where uname='$uname' and pass='$passwod'");

 

As it is inside " and not '

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.