function userLogin($userName, $md5Password) { $result = array(); $ec_salt = getEcsaltByUserName($userName); $result['validate'] = isUserValidated($userName, $md5Password, $ec_salt); die(urldecode(json_encode($result))); }
$result = array(); switch($type) { case 'ec_salt': $result['ec_salt'] = getEcsaltByUserName($userName); break; case 'user_validate': $result['validate'] = isUserValidated($userName, $password); break; } */ $result = array(); $ec_salt = getEcsaltByUserName($userName); $result['validate'] = isUserValidated($userName, $password, $ec_salt); die(urldecode(json_encode($result))); function getEcsaltByUserName($userName) { $sql = "SELECT ec_salt FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_name = '{$userName}'"; $ec_salt = $GLOBALS['db']->getOne($sql); $ec_salt = empty($ec_salt) ? -1 : $ec_salt; return $ec_salt; } function isUserValidated($userName, $password, $ec_salt) { $password = md5($password . $ec_salt); $sql = "SELECT user_id FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_name = '{$userName}' AND password='******'"; if ($GLOBALS['db']->getOne($sql)) { return 1; }