public function login() { if (IS_POST) { $user_name = I('post.user_name', '', 'htmlspecialchars'); $pwd = I('post.password', ''); if (empty($user_name) || empty($pwd)) { $this->error('Incorrect account address or password. Please try again.'); } $info = D('Users')->UserLogin($user_name, $pwd); if ($info) { set_cookies($info, $_POST['remember']); set_session($info); $this->success('Login successful.', U('index/index')); } $this->error('Incorrect account address or password. Please try again.'); } }
<?php include_once dirname(__FILE__) . "/../functions/users.php"; $username = convert_str($_POST['username']); $password = hash_password($_POST['password']); $ret = array(); if (!user_exist($username)) { $ret["code"] = 1; $ret["msg"] = "No such user!"; echo json_encode($ret); die; } if (!$current_user->set_user($username, $password)) { $ret["code"] = 1; $ret["msg"] = "Password incorrect!"; } else { $exp = time() + $_POST['cksave'] * 24 * 60 * 60; if ($_POST['cksave'] == 0) { $exp = 0; } set_cookies($username, $password, $exp); $current_user->update_last_login($username); $ret["code"] = 0; $ret["msg"] = "Success..."; } echo json_encode($ret);
$ret["msg"] = "Retype password doesn't match!"; echo json_encode($ret); die; } if (strcasecmp($current_user->get_val("password"), $ops)) { $ret["msg"] = "Wrong password!"; echo json_encode($ret); die; } if ($ps == "") { $ps = addslashes($_POST['ol_password']); } else { if (strlen($ps) < 3) { $ret["msg"] = "Password too short!"; echo json_encode($ret); die; } } $infos["password"] = $ps; $infos["email"] = $email; $infos["school"] = $school; $infos["nickname"] = $nickname; $current_user->update_info($infos); $ret["msg"] = "Success!"; $ret["code"] = 0; set_cookies($username, hash_password($ps)); echo json_encode($ret); } else { $ret["msg"] = "Invalid Request!"; echo json_encode($ret); }
function Finput($type = 'request', $field = null, $default = null, $time = null) { switch ($type) { //_REQUEST数据 case 'request': //GET方式请求 if ($_SERVER['REQUEST_METHOD'] == 'GET') { //方式 $urlencode = config('URL_ENCODE') ? config('URL_ENCODE') : false; if ($urlencode) { //GET方式判断是否URL编码 foreach ($_REQUEST as $key => $val) { //解码url参数 $_REQUEST[$key] = urldecode($val); } } } if (!empty($field)) { @($data = $_REQUEST[$field] ? $_REQUEST[$field] : $default); } else { @($data = $_REQUEST); } break; //_POST数据 //_POST数据 case 'post': if (!empty($field)) { @($data = $_POST[$field] ? $_POST[$field] : $default); } else { @($data = $_POST); } break; //_GET数据 //_GET数据 case 'get': //GET方式请求 $urlencode = config('URL_ENCODE') ? config('URL_ENCODE') : false; if ($urlencode) { //GET方式判断是否URL编码 foreach ($_GET as $key => $val) { //解码url参数 $_GET[$key] = urldecode($val); } } if (!empty($field)) { @($data = $_GET[$field] ? $_GET[$field] : $default); } else { @($data = $_GET); } break; //_PUT数据 //_PUT数据 case 'put': if (!empty($field)) { @($data = $_PUT[$field] ? $_PUT[$field] : $default); } else { @($data = $_PUT); } break; //COOKIE数据 //COOKIE数据 case 'cookie': if (!empty($field)) { @($data = $_COOKIE[$field] ? $_COOKIE[$field] : set_cookies($field, $default, $time)); } else { @($data = $_COOKIE); } break; //SESSION数据 //SESSION数据 case 'session': @session_start(); if (!empty($field)) { @($data = $_SESSION[$field] ? $_SESSION[$field] : $default); } else { @($data = $_SESSION); } break; //SERVER数据 //SERVER数据 case 'server': if (!empty($field)) { @($data = $_SERVER[$field] ? $_SERVER[$field] : $default); } else { @($data = $_SERVER); } break; } //递归转义数据 return _addslashes($data); }