Created
February 1, 2013 02:52
-
-
Save anthonycvella/4688799 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function login() | |
{ | |
global $HTTP_RAW_POST_DATA, $db; | |
// remove the second argument or pass false if you want to use an object | |
//$user_info = json_decode($HTTP_RAW_POST_DATA, false); | |
// Check for required parameters | |
if (isset($_POST['username']) && isset($_POST['passwordMD5'])) | |
{ | |
//Put parameters into local variables | |
$username = mysql_real_escape_string($_POST['username']); | |
$password = mysql_real_escape_string($_POST['passwordMD5']); | |
$db->query("SELECT password FROM users WHERE username=?")->bind(1, $username)->execute(); | |
if ($db->getTotalRows()) { | |
$result = $db->fetch(); | |
$resultpassword = $result['password']; | |
} | |
// Username or password invalid | |
if ($passwordMD5 == $resultpassword) { | |
$token = generateToken(); | |
header('Content-type: application/json'); | |
echo json_encode(array( | |
'username' => $username, | |
'token' => $token | |
)); | |
/*sendResponse(200, json_encode(array( | |
'username' => $username, | |
'token' => $token | |
)));*/ | |
return true; | |
} else { | |
sendResponse(400, 'Invalid Username or Password'); | |
return false; | |
} | |
} | |
//sendResponse(401, 'Not enough parameters'); | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment