Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Need Help...again............, Authentication -_-
HmmZ
post Mar 29 2005, 10:00 PM
Post #1


Super Member
*********

Group: Members
Posts: 362
Joined: 2-March 05
From: The Netherlands
Member No.: 4,097



Ok, vizskywalker was finally able to solve the problem with my registration, but when I tried to login with my testaccount, it just continuously give me the "wrong username/password" error, i registered a new account and tried again, but still fails...

here's the authentication page...:
CODE
<?php

$user = $_POST['username'];
$pass = $_POST['password'];

$user=strip_tags($user);
$pass=strip_tags($pass);

$user=str_replace(" ","",$user);
$pass=str_replace(" ","",$pass);
$user=str_replace("%20","",$user);
$pass=str_replace("%20","",$pass);

$user=addslashes($user);
$pass=addslashes($pass);

$conn = mysql_connect("localhost","***","***");

mysql_select_db("***");

$pass=md5($pass);

$request = "SELECT * FROM go_logintable WHERE password='$pass' AND username='$user'";

$results = mysql_query("$request",$conn);

if(mysql_num_rows($results)==0)
{
echo "Username/Password Incorrect";
$_SESSION['auth'] = false;

}
else
{
echo "Succesfully logged in";
$_SESSION['user'] = $user;
$_SESSION['auth'] = true;
}
?>

I don't know if it matters, but the registration also uses $password=md5($password), so the password is already encoded, like i said, i dont know if that matters.

also, since the error i get is displayed with
CODE
if(mysql_num_rows($results)==0)
maybe the problem is there..


[And again...sorry im bugging you guys..again sad.gif]
Go to the top of the page
 
+Quote Post
Spectre
post Mar 30 2005, 11:33 AM
Post #2


Privileged Member
*********

Group: Members
Posts: 874
Joined: 30-July 04
Member No.: 246



It does matter. Unless you can hash strings in MD5 in your head, I'm assuming you are entering your password in plain-text - so basically, the plain-text password is going to be compared to the hashed password, meaning they won't match.

Try using:
CODE
$pass = md5($pass);

(assuming you haven't used a custom salt) after '$pass=addslashes($pass);'.

Also, just a tip - where possible, use a single quote instead of a double quote, as it is quicker and less memory intensive. Strings within double quotes are checked for variables, escape characters, special formatting etc, so it takes longer to process. You could also use urldecode() instead of checking for '%20'.

For example:
CODE
$user = urldecode($user);
$pass = urldecode($pass);
$user=str_replace(' ','',$user);
$pass=str_replace(' ','',$pass);


Oh, and you want to be careful when passing user-entered values directly to a MySQL query. It can create all sorts of problems of the security kind.
Go to the top of the page
 
+Quote Post
Spectre
post Mar 30 2005, 11:36 AM
Post #3


Privileged Member
*********

Group: Members
Posts: 874
Joined: 30-July 04
Member No.: 246



That it is to say, it's better to use single quotes if you can. There are obviously many situations in which the alternative is required.

(We need an edit button.)
Go to the top of the page
 
+Quote Post
HmmZ
post Mar 30 2005, 11:52 AM
Post #4


Super Member
*********

Group: Members
Posts: 362
Joined: 2-March 05
From: The Netherlands
Member No.: 4,097



I ám using that code ($pass=md($pass)wink.gif look again wink.gif

What I meant, was that with the registration, the password will come hashed into the table, and I thought with the login it would then require to insert the hashed password (a whole different password then the user wanted..), so basically, im using the md5 in the registration ánd with the login, and theres where my question earlier comes in, does thát matter?

and could you tell me what a custom salt is?
I've heard about it before, but i don't know what people mean by that smile.gif

and thanks for the tip on single quotes and the urldecode()
QUOTE
Oh, and you want to be careful when passing user-entered values directly to a MySQL query. It can create all sorts of problems of the security kind.
??
Their values go through some stripping first don't they? Once stripped and secured from sql injection, then the values are send through a query, so why wouldn't this be secure? unsure.gif
Go to the top of the page
 
+Quote Post
Spectre
post Mar 30 2005, 12:30 PM
Post #5


Privileged Member
*********

Group: Members
Posts: 874
Joined: 30-July 04
Member No.: 246



Heh, I didn't notice the MD5 hashing. My apologies.

It goes through some stripping, but certainly not enough to be considered secure.

A 'salt' is bascially just a random generation used in conjunction with the cipher key, essentially causing the end result to be harder to break. If you are using the md5() function alone, then you shouldn't need to worry about it.

I not 100% sure what you're asking in regard to comparing hashed values. If you encrypt the password entered in registration and then store that encrypted value in the database, then yes, you need to encrypt it again when entered during login for comparison. The password entered by the user will obviously not be in an encrypted form, so you can't compare a raw value against an encrypted value and come out positive. I think that's what you're asking about.

Because there are no visible errors in the script shown here, I am going to assume that the problem lies either in the registration script, or your database structure. Try looking into both of these.
Go to the top of the page
 
+Quote Post
HmmZ
post Mar 30 2005, 02:55 PM
Post #6


Super Member
*********

Group: Members
Posts: 362
Joined: 2-March 05
From: The Netherlands
Member No.: 4,097



I've send you a PM, read and think about it please smile.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Authentication - Authorization Server(0)
  2. Smtp Authentication Error [resolved](3)
  3. Mysql Authentication Problems(11)
  4. Http Authentication Without Using The Popup(3)
  5. Http Authentication(2)
  6. Email Address Authentication Problem(1)
  7. Ftp Script Problems - Authentication Failure(3)
  8. 535 Incorrect authentication data(4)


 



- Lo-Fi Version Time is now: 8th October 2008 - 05:07 AM