Note that there are some explanatory texts on larger screens.

plurals
  1. POusername and password passed as integers rather than strings
    primarykey
    data
    text
    <p>I'm creating a login script and its failing each time even when I input the correct credentials. I firstly thought this was to do with the crypt function which has been explained in depth and have done further research upon to find a good method. </p> <p>Anyway I have remove the crypt function in both the login and register to test the login script. Upon removing this I still got an error which stated <code>Invalid username or password</code>. </p> <p>I wanted to see what was actually been passed in my <code>POST</code> variables, so I echoed these variables as they are defined e.g. </p> <p><code>$username = isset($_POST['username']);</code></p> <p><code>echo $username;</code></p> <p>outputs: <code>1</code></p> <p>however </p> <p><code>echo $_POST['username'];</code></p> <p>outputs <code>admin</code> (which is the username I have been using)</p> <p>If I remove the isset from this POST variable then I am returned with the true value but this still fails my login script.</p> <p>I don't understand whats going wrong as I've used this same statement in a different function to test it and it works, instead of using POST variables I am already setting the username and password and then wrapping in a foreach statement and this works.</p> <p>It must be something to do with my POST variables and the way I am handling it but I don't have the experience/knowledge to solve the problem. I can't understand why my POST data is returned as a integer but then even when I remove the isset tag my statement is still false?</p> <p>Any input and help is greatly welcomed and appreciated.</p> <p>Below is my code, if there's anything else required please ask:</p> <p>index.php</p> <pre><code>&lt;form id="loginForm" method="POST" action="classes/class.Login.php"&gt; &lt;input type="text" id="username" name="username" placeholder="Username"/&gt; &lt;input type="password" id="password" name="password" placeholder="Password" class="showpassword"/&gt; &lt;input type="submit" name="submit" value="Log in"/&gt; </code></pre> <p>classes/class.Login.php</p> <pre><code>public function loginuser() { $username = isset($_POST['username']); $password = isset($_POST['password']); //$salt = "boo"; //$pw = crypt($password, $salt); $stmt = $this-&gt;pdo-&gt;prepare("SELECT * FROM users WHERE username = :username AND password = :password LIMIT 1"); $stmt-&gt;bindValue(":username", $_POST['username'], PDO::PARAM_STR); $stmt-&gt;bindValue(":password", $_POST['password'], PDO::PARAM_STR); if ($stmt-&gt;fetch(PDO::FETCH_ASSOC)) { $_SESSION['authorized'] = true; $_SESSION['username'] = $username; header('Location: testloginrequired.php'); } else { echo "Invaild username or password. Try again"; } }// end loginuser </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload