Jump to content

PHP Password Check


Dees

Recommended Posts

I am trying to create a PHP script that will check to see if the password that was input into a form. Here is the code that I have created so far.This is the code for the HTML page: <form action="handle_password.php" method="post"> Pleae Enter the Password: <input name="password" type="text" size="20" /> </form>This is the code for the PHP page <?php $password; $cpassword = 'pass1'; if($password == $cpassword); {print "Correct Password"}; else {print "Wrong Password"}; ?>I am trying to make the password that was input check against the correct password but I get an error on the line:

Link to comment
Share on other sites

You forgot the line...But you have many ("obvious") problems with your code, for example missplaced semi-colons (; ).Here's how it should look:

<?php$password = $_POST['password'];$cpassword = 'pass1';if ($password == $cpassword) {	print "Correct Password";} else {	print "Wrong Password";}

Ex: If you have a semi-colon after the if-statement if (...); that means you end the "entite if-statement", so the else-statement is then "unvalid", as it's no "open" if-statement...You also don't need semi-colons after blocks ({ ... };). Semi-colons doesn't stand for end-of-line, it stands for end-of-statement. Consider this:

// Calls to some random functionsfoo(); bar(); myFunc(); print('Hello!!'); if ($myVar) print('true');

Even if it's all on one line, it's still valid (it wouldn't be if we removed any semi-colon), but as it's hard to read and can be confusing it's better to write it like this:

// Calls to some random functionsfoo();bar();myFunc();print('Hello!!');if ($myVar)	print('true');

I would also recommend that you change the field-type to password..EDIT: Sorry, missed the other post..

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...