int checkPass ( string $user , string $password )
Write a PHP function “checkPass” that takes two arguments: $user and $password and returns the UserID if the password matches the MD5 encoding of the appropriate password in the interview_user_info table below and -1 otherwise.
The $user variable contains the NetID of the individual; the $password variable contains a clear-text version of the password as submitted.
±--------------------------------------------------------------------------------+
| interview_user_info |
±----------±------------±----------±-------±---------------------------------+
| UserID | LastName | FirstName | NetID | Passwd |
±----------±------------±----------±-------±---------------------------------+
| 469562029 | Gonzalez | Shauntee | sgonz | 530b4a0ae65148d112537bc0eafba9c9 |
| 702930431 | Bates | Austin | abates | 9cdfb439c7876e703e307864c9167a15 |
±----------±------------±----------±-------±---------------------------------+
The connection and database selection are taken care of. Write the query to pull data from the table “interview_user_info”, and return the result. The connection will be closed for you.
Hint: You will likely need to make use of the following functions and possibly others: md5, mysql_query, mysql_fetch_assoc
Code Editor
Ive been bouncing around so many times but I jst cant seem to get anything to work. Here is what I currently have but it has changed a lot.
<? function checkPass($user, $passord) { $query = "SELECT Passwd FROM interview_user_info WHERE NetID = '$user'"; $result = mysql_query($query); $passwordArr['Passwrd'] = mysql_fetch_assoc($result); $passTest = md5($password); $query2 = "SELECT UserID FROM interview_user_info WHERE NetID = '$user'"; $result2 = mysql_query($query2); $userIDArr['UserID'] = mysql_fetch_assoc($result2); //print_r(array_values($userIDArr)); //print_r(current($userIDArr)); return $result; } ?>