Jump to content

need a little help


Guest nameless1

Recommended Posts

Guest nameless1

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 ?  :confused:

 

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!

Link to comment
Share on other sites

Guest nameless1

Figured it out.

 

I randomly given the db table password length 11 characters. It wasn't enough to store the encrypted password.

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.