Jump to content

Comparing passwords with php

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
I'm currently making a registration form on a website. Everything went fin until I changed the password's textbox to the password type.

<input type='password' name='rPass1' />


All things below I need help with works if It got the type text.


I want to compare if two passwords are the same:

if $_POST["rPass1"] != $_POST["rPass2"] || empty($_POST["rPass2"]))

and be able to store the password in a MySQL server:

mysql_query("INSERT INTO Users (Name, Password, Email, Referer)

VALUES ('$_POST[rName]', '$_POST[rPass1]', '$_POST[rEmail1]', '$_POST[rReferer])");

and then be able to receive it again:

$result = mysql_query("SELECT * FROM Users where Name='$username'");

while($row = mysql_fetch_array($result))

{

  if ($row['Password']==$password)

  echo "yay"


}

Can someone please help me with this?

#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Which part is not working?

Try and print things out until your isolate the problem I suppose.

Put this at the top
print_r($_POST);

echo something IF the passwords are the same and is not empty (I think you have if it is empty so you may wanna put a ! before that statement

if you do that you can ensure you are making a query

at the end of the query put an "or die(mysql_error())" so you can see what error you may or may not be getting on bot those queries.

#3
relapse

relapse

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 476 posts
Holy ballz:
VALUES ('$_POST[rName]', '$_POST[rPass1]', '$_POST[rEmail1]', '$_POST[rReferer])");

SQL injection anyone?

#4
sdavis2702

sdavis2702

    Learning Programmer

  • Members
  • PipPipPip
  • 93 posts
How would you protect yourself from SQL injection in this case? Like what would that line of code look like protected?
My Name is Sean and I like codes and stuff...
NoobJunction.com | SuccessOnMyMind.com | ArmedForcesCarClub.com

#5
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
watch out theres a missing "(" here after the "if"
if $_POST["rPass1"] != $_POST["rPass2"] || empty($_POST["rPass2"]))

also storing passwords as plain text is highly discouraged
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#6
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Aw come on guys be nice. For one I am sure this is a personal project not something that would go public, two, is that really something you have to add when you yourself are playing with it? I would try to get it to work first, then add security.

#7
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
we are helping here :amr:
btw changing the input type into a password shouldn't make a difference it works the same as "text" input, it just hides the password.
try dumping the $_GET or $_POST, and seeing if the password field is there:

var_dump($_GET);

also inputs without names are the only ones that doesn't get submitted
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#8
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts

BlaineSch said:

Which part is not working?

Try and print things out until your isolate the problem I suppose.

Put this at the top
print_r($_POST);

echo something IF the passwords are the same and is not empty (I think you have if it is empty so you may wanna put a ! before that statement

if you do that you can ensure you are making a query

at the end of the query put an "or die(mysql_error())" so you can see what error you may or may not be getting on bot those queries.

It doesn't work. When I try to print the password it only prints an empty string.

amrosama said:

watch out theres a missing "(" here after the "if"
if $_POST["rPass1"] != $_POST["rPass2"] || empty($_POST["rPass2"]))

also storing passwords as plain text is highly discouraged

This is my problem, I know how to get all this working as plain text. My whole question was how to do it with a password.

amrosama said:

we are helping here :amr:
btw changing the input type into a password shouldn't make a difference it works the same as "text" input, it just hides the password.
try dumping the $_GET or $_POST, and seeing if the password field is there:

var_dump($_GET);

also inputs without names are the only ones that doesn't get submitted

The thing is. It worked fine until I changed the type, so it must make a difference.

#9
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
Thanks for all the help everyone. I don't really get what all of you mean though, I started with MySQL and PHP two days ago after all.

The error where in a row a little bit earlier.

I had this code:

if (strlen($_POST["rName"]) < 4 ||  strlen($_POST["rName"]) > 15)
$invalid_name='true';

and approximately at the same time I changed the type to password I changed it to this:

if ($_POST["rName"]="" || strlen($_POST["rName"]) < 4 ||  strlen($_POST["rName"]) > 15)
$invalid_name='true';

When it should be like this:

if ($_POST["rName"]=="" || strlen($_POST["rName"]) < 4 ||  strlen($_POST["rName"]) > 15)
$invalid_name='true';


I feels a little bit stupid now but I'm glad it worked.