Jump to content


Photo

Password Validation


  • Please log in to reply
4 replies to this topic

#1 Schlo_50

Schlo_50
  • Members
  • PipPipPip
  • Advanced Member
  • 468 posts

Posted 26 September 2006 - 03:30 PM

To add some validation to my register form, i thought it would be a good idea to make the end user re-enter their chosen password in order for it to be correct. But im not sure what the line of code would be to only allow the form to be submitted if the passwords match.

<?php
$self=$_SERVER['PHP_SELF'];
$firstname=$_POST['first_name'];
$surname=$_POST['sur_name'];
$username=$_POST['user_name'];
$password=$_POST['password'];
$rpassword=$_POST['password'];
?>
<center><form action="blah blah" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="sur_name"><br>
Username: <input type="text" name="user_name"><br>
Password: <input type="password" name="password"><br>
Re-Password: <input type="password" name="password"><br>
<input type="Submit">
</form></center>

<?php

{
$conn = mysql_connect( "localhost","username","password" )
or die( "Err:Conn" );
$rs = mysql_select_db( "dombar0_work", $conn )
or die( "Err:Db" );
$sql = "INSERT INTO users ( first_name,sur_name,user_name,password ) VALUES
( \"$firstname\",\"$surname\",\"$username\",
                             password(\"$password\") )";

$rs = mysql_query( $sql, $conn );
if ($rs){ echo( "Details Added Successully $username" ); }
}
?>

I assume i need an if statement before the '$conn' line? Could someone give me the line that will check to see if the passwords match before connecting to the database please? Thanks guys!

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 26 September 2006 - 03:36 PM

if ($password == $rpassword) {
  // connect and do insert
}


#3 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 26 September 2006 - 03:40 PM

$password=$_POST['password'];
$rpassword=$_POST['password'];

You are also using the same post on both variables, it will always match..........

rename the second password-field to rpassword or whatever and post declare it

#4 Schlo_50

Schlo_50
  • Members
  • PipPipPip
  • Advanced Member
  • 468 posts

Posted 26 September 2006 - 03:42 PM

I noticed that after i posted it, lol I still need the line of code to validate the password and the re-entering of the password though.

#5 Schlo_50

Schlo_50
  • Members
  • PipPipPip
  • Advanced Member
  • 468 posts

Posted 26 September 2006 - 03:43 PM

Sorry. Ignore that last post. Me and my chronic blindness.

:P




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users