Jump to content

[SOLVED] problem with password encryption


gli

Recommended Posts

<?php include "databasec.php" ?> 
<?php  
   function confirm_query($result_set) { 
       if (!$result_set) { 
           die("Database query failed: " . mysql_error()); 
       } 
   } 
   ?> 

<?php 
$username = $_POST['username']; 
$password = $_POST['password']; 
$hashedpassword = sha1($password); 

$query = "SELECT *"; 
$query .= "FROM users "; 
$query .= "WHERE username = '{$username}' "; 
$query .= "AND hashedpassword = '{$hashedpassword}' "; 
$query .= "LIMIT 1"; 
$result_set = mysql_query($query); 
confirm_query($result_set); 
if (mysql_num_rows($result_set) == 1) { 
$found_user = mysql_fetch_array($result_set); 
echo logged in; 
} else { 
$message = "Username/password incorrect. <br /> 
Please make sure your caps lock key is off and try again."; 
echo $message; 
} 
?> 

 

<?php include "databasec.php" ?> 
<?php 
$username = $_POST['username']; 
$password = $_POST['password']; 
$passwordagain = $_POST['passwordagain']; 
$email= $_POST['email']; 
$country= $_POST['country']; 
$check = $_POST['check']; 
$hashedpassword = sha1($password); 

 if ((((((( $username != NULL )  
   && ( $password != NULL )     
   && ( $passwordagain != NULL )  
   && ( $password == $passwordagain )  
   && ( $check == "neesmu" )  
   && ( $email != NULL ))))))) {  

mysql_query("INSERT INTO users  
(username,hashedpassword,email,country) VALUES('$username','$hashedpassword','$email','$country') ")  
or die(mysql_error()); 
   echo "registered"; } else { 
   echo "error in form"; 
} 


?> 

 

 

Hi! I didnt add form files like register.php and login.php, but these which i added are the process files.

I have problem that i cant login with my registered username and password.

But when i remove $hashedpassword entry and change with password then all is okey, mhm and all script running without password encryption. But when as in these codes i add password encryption then i cant login.

Where is the problem?

 

Sorry for my bad english.

Link to comment
https://forums.phpfreaks.com/topic/101355-solved-problem-with-password-encryption/
Share on other sites

yes okey, but again cant log in. Something maybe is wrong with logincheck.php   , maybe something there, hmm   i tried to echo in that error login message this $hashedpassword and that printed like the encrypted one in the database is. but whay in the process it cant find that $hashedpassword is equal to database record.

 

EDITED:

oh i just was reading other topic in this forum with similar problem, and there was one great reply :) check your database entry if there is big enough space for encrypted password.

 

EDITED2x:

yes there were only 30char space :D hmm by brain already told that but i didnt hear. ok thnx problem solved.

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.