1

Suppose I have a database table consisting of three columns - Userid, Username & Password. And let's assume I am building a Log-in Form and the password is stored in encrypted form. So, before it can be compared with the original password, it needs to be processed a little.

So, I let the user enter the username and password in the form.

include('db.php');      
$getuid = $connection->prepare('SELECT FROM users WHERE username = :u');
$getuid->execute(array("u" => $_REQUEST['username']));

Now, I have executed the statement, and the row with the Entered Username is selected.

What I Want to Do ?

After Selecting the Row, I want the corresponding Password(which is in encrypted form) and Userid to be stored in $pass, $userid variables. How can I do that?

KatieK
  • 13,586
  • 17
  • 76
  • 90
Rohitink
  • 1,154
  • 3
  • 14
  • 21

2 Answers2

1

the select query needs to be $getuid = $connection->prepare('SELECT * FROM users WHERE username = :u'); where * selects/gets all columns from the table users.

Then traverse the results, as per their column names (username, and say pwd) to get their corresponding values, as shown below:

    $results = $stmt->fetch(PDO::FETCH_ASSOC);
    foreach ( $results as $v) {
     $username = $v['username'];
     $pwd = $v['pwd']; 
     }

Note: you cannot retrieve the original or decoded password, its explained nicely here

Community
  • 1
  • 1
Teena Thomas
  • 5,139
  • 1
  • 13
  • 17
0

If user enters a username as uname,then use this query to get

select password,userid from users where user_name=uname
AnandPhadke
  • 13,160
  • 5
  • 26
  • 33