gli Posted April 16, 2008 Share Posted April 16, 2008 <?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 More sharing options...
zenag Posted April 16, 2008 Share Posted April 16, 2008 use base64_encode &base64_decode for this type... Link to comment https://forums.phpfreaks.com/topic/101355-solved-problem-with-password-encryption/#findComment-518402 Share on other sites More sharing options...
gli Posted April 16, 2008 Author Share Posted April 16, 2008 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 hmm by brain already told that but i didnt hear. ok thnx problem solved. Link to comment https://forums.phpfreaks.com/topic/101355-solved-problem-with-password-encryption/#findComment-518577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.