help with password

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
slack
Forum Newbie
Posts: 2
Joined: Mon Aug 22, 2011 5:13 pm

help with password

Post by slack »

I want to use multiple passwords for a webpage using an include link.
I am trying to use password= password1 or password2:
$password = ("sunju") || ("cancer");
but does not work, works with only one.
Using code below on the webpage
<?php

// If password is valid let the user get access
if (isset($_POST["password"]) && ($_POST["password"]=="$password")) {

?>

<?php
}
else
{
// Wrong password or no password entered display this message
if (isset($_POST['password']) || $password == "") {
print "<p align=\"left\"><font color=\"red\"><b>Incorrect Password</b><br>Please enter the correct password</font></p>";}
print "<form method=\"post\"><p align=\"left\">Please enter your password for access <b>(must be in lower case)</b><br>";
print "<input name=\"password\" type=\"password\" size=\"25\" maxlength=\"20\"><input value=\"Login\" type=\"submit\"></p></form>";
}

?>
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: help with password

Post by twinedev »

Code: Select all

if ($password=='sunju' || $password=='cancer') {
slack
Forum Newbie
Posts: 2
Joined: Mon Aug 22, 2011 5:13 pm

Re: help with password

Post by slack »

Thankyou
i have fixed the problem:
<?php

// If password is valid let the user get access

if (($_POST["password"])=='sunju' || ($_POST["password"])=='cancer') {


?>

Content here

<?php
}
else
{
// Wrong password or no password entered display this message

if (($_POST["password"] ) || $_POST["password"] ==="" ) {

print "<p align=\"left\"><font color=\"red\"><b>Incorrect Password</b><br><b>Or you did not enter anything</b><br></font><font color=\"yellow\">Please enter the correct password</font></p>";}

print "<form method=\"post\"><p align=\"left\">Please enter your password for access <b>(must be in lower case)</b><br>";
print "<input name=\"password\" type=\"password\" size=\"25\" maxlength=\"20\"><input value=\"Login\" type=\"submit\"></p></form>";
}

?>
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: help with password

Post by phphelpme »

Your saving standard text passwords which is not secure at all. I suggest you md5/sha1 hash them at least even if you are not using a database. Then you can md5/sha1 the user input and check your md5/sha1 hash string for validation.

Best wishes
Post Reply