Jump to content

[SOLVED] More than 1 password


web_master

Recommended Posts

hi,

 

I got a password protected page. How can I give a more tha one password?

 

Now is a password "admin", but I want to use the other words too...

 

thnx

 

<?php
// Password
$password = "admin";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Password protected area</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
p {
font-size: 9px;
color: #000000;
font-family: Verdana, Tahoma, Arial
}

td {
font-size: 9px;
color: #000000;
font-family: Verdana, Tahoma, Arial
}
-->
</style>
</head>
<body>
<?php 
print "<h2 align=\"center\">Password protected area</h2>";

// If password is valid let the user get access
if (isset($_POST["password"]) && ($_POST["password"] == $password)) {
?>
<!-- hidden contents -->

  <p align="center">Password is correct</p>

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

?>
<br />
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/110102-solved-more-than-1-password/
Share on other sites

Setup an array of possible passwords then check to see if the provided password is in the password array

 

// set up array of possible passwords
$passwords = array('pass1', 'pass2', 'pass3', 'etc..');

...

// check to see if the provided password is in the password array
if (isset($_POST["password"]) && (in_array($_POST['password'], $passwords)) 
{
    // user logged in!
}

Setup an array of possible passwords then check to see if the provided password is in the password array

 

// set up array of possible passwords
$passwords = array('pass1', 'pass2', 'pass3', 'etc..');

...

// check to see if the provided password is in the password array
if (isset($_POST["password"]) && (in_array($_POST['password'], $passwords)) 
{
    // user logged in!
}

 

This is what I got:

 

Warning: Wrong parameter count for in_array() in d:\internet\pass.php on line 32

 

<?php
// Password
$passwords = array('admin', 'powerg3');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Password protected area</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
p {
font-size: 9px;
color: #000000;
font-family: Verdana, Tahoma, Arial
}

td {
font-size: 9px;
color: #000000;
font-family: Verdana, Tahoma, Arial
}
-->
</style>
</head>
<body>
<?php 
print "<h2 align=\"center\">Password protected area</h2>";

// If password is valid let the user get access
if (isset($_POST["password"]) && (in_array($_POST["password"]) == $passwords)) {
?>
<!-- hidden contents -->

  <p align="center">Password is correct</p>

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

?>
<br />
</body>
</html>

<?php
// set up array of possible passwords
$passwords = array('pass1', 'pass2', 'pass3', 'etc..');

// check to see if the provided password is in the password array
if (isset($_POST["password"]) && (in_array($_POST['password'], $passwords))) 
{
    // user logged in!
}

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.