Log in

View Full Version : Need help with Login script



allahverdi
08-13-2007, 06:07 AM
Hello
I have on login script (if, else)
here is my script:

<?php
require_once 'config.php';
require_once 'functions.php';

$errMsg = '';
if (isset($_POST['txtUserid'])) {

// Check the user login. For now we only check it
// against a hardcoded value
if ($_POST['txtUserid'] == 'azservice' && $_POST['txtUserpw'] == 'azservice') {
$_SESSION['isLogin'] = true;

header('Location: admin.php');
exit;
}


else {
$errMsg = "Wrong Id/Password";
}
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p>&nbsp;</p>
<?php
if ($errMsg != '') {
echo '<p align="center"><font color="#990000">' . $errMsg . '</font></p>';
}
?>
<form action="" method="post" name="frmCampaign" id="frmCampaign">
<table align="center" width="500" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="200" bgcolor="#336699"><font color="#FFFFFF"><strong>User Id</strong></font></td>
<td bgcolor="#FFFFFF"><input name="txtUserid" type="text" id="txtUserid" value=""></td>
</tr>
<tr>
<td width="200" bgcolor="#336699"><font color="#FFFFFF"><strong>Password</strong></font></td>
<td bgcolor="#FFFFFF"><input name="txtUserpw" type="password" id="txtUserpw" value=""></td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#FFFFFF"> <input type="submit" name="Submit" value="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>

there is no problem now buy i need to make 2 users:


if (isset($_POST['txtUserid'])) {
if ($_POST['txtUserid'] == 'azservice' && $_POST['txtUserpw'] == 'azservice') {
$_SESSION['isLogin'] = true;

header('Location: admin.php');
exit;
}

how can i make that for 2 users?
help me please

Twey
08-13-2007, 08:25 PM
You might want to try a database backend. Here's one I made earlier. (http://www.twey.co.uk/?q=loginscript)

alexjewell
08-13-2007, 09:46 PM
I made an array with all the usernames:



$users = array('alex','twey','bob','awesome','guest');
$passwords = array('alexPass','tweyPass','bobPass','awesomePass','guestPass');

if(isset($_POST['user']) && isset($_POST['pass'])){
$user = $_POST['user'];
$pass = $_POST['pass'];

if(in_array($user,$users) && in_array($pass,$passwords)){
// set the session and stuff here
}

else{
// error message
}
}

else{
// whatever
}

Twey
08-13-2007, 11:03 PM
This implementation is broken: a user could log in with any username and any password, e.g. alex:bobPass.
if(in_array($user, $users) && array_search($user, $users, true) === array_search($pass, $passwords, true)) {