Jump to content

[SOLVED] username password check failing?!


dvd871

Recommended Posts

This is killing me.  I have used this code dozens of times in various scripts but now all of a sudden it fails.

 

The simple form:

<html>
<head>
<title><?=$config['game_name']?></title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table style="width: 80%; text-align: left; margin-left: auto; margin-right: auto;">
<tr><td style="width: 50%;">About Your Game Name - Put a short description of your game here.</td>
<td><form action="login.php" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="submit" value="Submit"></form></td></tr>
<tr><td> </td><td><h3><a href="register.php">REGISTER NOW!</a></h3></td></tr></table>
</body>
</html>

 

The login.php:

<?php
$err = "";  
$username = stripslashes($_POST['username']);
$password = stripslashes($_POST['password']);

// Check both username and password were supplied
if((!$username) || (!$password)) {
    $err.="Please enter ALL of the information! <br />";
    include "error.php";
    exit;
}
// Check for invalid character in the username
elseif(!preg_match("/^[\\w-_]*[\\w-_]$/", $username)) {
    $err.="Your user name contains invalid characters";
    include "error.php";
    exit;
}
// Check for invalid character in password
elseif(!preg_match("/^[\\w-_]*[\\w-_]$/", $password)) {
    $err.="Your password contains invalid characters";
    include "error.php";
    exit;
}
?>

 

I have verified that the username and password are set after setting the initial variables.  The code barfs on the if((!$username) || (!$password)) {  It keeps telling me "Please enter ALL of the information!"  I am using php 4.4.7, mySQL 4, apache 1.3x 

Link to comment
Share on other sites

Now I know the second suggestion should have worked since its checking to see if the string length is greater than 1 but its still is failing!

 

--Edit:

output of $username snd password right before the first check:

#DEBUG: admin

#DEBUG: password

Link to comment
Share on other sites

Yea, it must have been something messed up in php.  I reinstalled XAMPP and it works fine now.  What a waste of an hour.  Stuff like this only happen to you when you are under the gun and must complete something...  ;D

 

Thanks for the quick replies.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.