Guest nameless1 Posted April 29, 2012 Share Posted April 29, 2012 Hy 2 all, I'm trying to write a registration/login system but I seem to have an error i cannot find. I'm using sha1 encryption for the password. The registration works like a charm. It inserts the users info + the encrypted password without any errors. BUT when i try to login it doesn't work. The thing is that when i remove the encryption (from the registration and the login), I can register and login just fine. Does anyone have any ideas ? I am using Aptana Studio 3 and XAMPP 1.7.7 Here are the codes: REGISTRATION: <?php include('config.php'); if($_SERVER['REQUEST_METHOD'] == 'POST'){ $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string(sha1($_POST['password'])); if(empty($username)){ echo("You must fill in a username!"); }else{ if(empty($password)){ echo("You must fill in a password!"); }else{ $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $rows = mysql_num_rows($query); if($rows > 0){ die("Username taken!"); }else{ $user_input = mysql_query("INSERT INTO users (username, password) VALUES ('$username' , '$password')"); echo "Succesfully registered!"; } } } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Register</title> </head> <body> <form action="register.php" method="post" /> Username: <input type="text" name="username" /><br /> Password: <input type="password" name="password" /><br /> <input type="submit" value="Register!" /> </body> </html> and here is the LOGIN: <?php include('config.php'); if($_SERVER['REQUEST_METHOD'] == 'POST'){ $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string(sha1($_POST['password'])); $query = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'"); $query_rows = mysql_num_rows($query); if($query_rows > 0){ echo "Succesfull login!"; session_start(); $_SESSION['login'] = "1"; }else{ echo "Bad login!"; } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Login</title> </head> <body> <form action="login.php" method="post" /> Username: <input type="text" name="username" /><br /> Password: <input type="password" name="password" /><br /> <input type="submit" value="Login!" /> </body> </html> Thanks in advanced! Quote Link to comment https://forums.phpfreaks.com/topic/261808-need-a-little-help/ Share on other sites More sharing options...
Guest nameless1 Posted April 29, 2012 Share Posted April 29, 2012 Figured it out. I randomly given the db table password length 11 characters. It wasn't enough to store the encrypted password. Quote Link to comment https://forums.phpfreaks.com/topic/261808-need-a-little-help/#findComment-1341559 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.