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
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());
?>

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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')

Link to comment
Share on other sites

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 '

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.