public function dologin() { if ($this->user['id']) { // $this->Redirect('','','',1); } $request_name = 'username'; $request_password = '******'; $request_email = 'email'; $user_name = addslashes($this->input[$request_name]); $password = addslashes($this->input[$request_password]); if (!$user_name && !$password) { $this->ReportError($this->lang['nameerror']); } $email = addslashes($this->input[$request_email]); $member = uc_user_login($user_name, $password); $timestamp = TIMENOW; // uid 大于0 登录成功,-1 : 用户不存在,或者被删除 -2:密码错误 其他:未定义 if ($member[0] > 0) { //同步登录 $ucsynlogin = uc_user_synlogin($member[0]); hg_set_cookie('user', $member[1], $timestamp + 31536000); hg_set_cookie('pass', $member[4], $timestamp + 31536000); hg_set_cookie('member_id', $member[0], $timestamp + 31536000); $this->Redirect($this->lang['loginsucess'], '', 2, 0, $ucsynlogin); } else { $this->ReportError($this->lang['nameerror']); } }
/** * 验证登录账号、密码、验证码,同过的话进行登录处理 * * @param string $username 用户名 * @param string $password 密码 * @param string $checkcode 验证码 * @param int $usecookie 是否记录到cookie,下次自动登录。0表示不记录,大于0表示cookie保存时间 * @param bool $encode 密码是否已经加密,默认否 * @param bool $needcheck 是否需要验证码,默认是 * @access public * @return int 0 正常, -1 用户名为空 -2 密码为空 -3 用户名或者密码为空 -4 用户名不存在 -5 密码错误 -6 用户名或密码错误 -7 验证码错误 -8 帐号已经有人登陆 -9 用户属于游客组 */ function jieqi_logincheck($username = '', $password = '', $checkcode = '', $usecookie = 0, $encode = false, $needcheck = true) { $ret = jieqi_loginpass($username, $password, $checkcode, $usecookie, $encode, $needcheck); if (is_object($ret)) { return jieqi_loginprocess($ret, $usecookie); } elseif ($ret == -10) { //临时用户,未设置密码,ucenter存在时候自动更新密码,否则返回密码错误 include_once JIEQI_ROOT_PATH . '/include/funuser.php'; if (function_exists('uc_user_login')) { list($uid, $uname, $upass, $uemail) = uc_user_login($username, $password); if ($uid > 0) { include_once JIEQI_ROOT_PATH . '/class/users.php'; $users_handler =& JieqiUsersHandler::getInstance('JieqiUsersHandler'); $userobj = $users_handler->getByname($username); if (is_object($userobj)) { $userobj->setVar('pass', $users_handler->encryptPass($upass)); $userobj->setVar('email', $uemail); $users_handler->insert($userobj); return jieqi_loginprocess($userobj, $usecookie); } } } return -5; } else { return $ret; } }
public function authenticateUC() { //通过接口判断登录帐号的正确性,返回值为数组 list($uid, $username, $password, $email) = uc_user_login($this->username, $this->password); setcookie('Example_auth', '', -86400); if ($uid > 0) { //用户登陆成功,设置 Cookie,加密直接用 uc_authcode 函数,用户使用自己的函数 setcookie('Example_auth', uc_authcode($uid . "\t" . $username, 'ENCODE')); //生成同步登录的代码 $ucsynlogin = uc_user_synlogin($uid); $user = User::model()->findByPk($uid); $this->_id = $user->id; $this->setState('email', $user->email); //$this->setState('role', '管理员'); //保存登录记录 $arr = array('uid' => $user->id, 'login_time' => strtotime('NOW'), 'login_ip' => Yii::app()->request->userHostAddress); $model = new LoginRecord(); $model->attributes = $arr; $model->save(); $this->errorCode = self::ERROR_NONE; } elseif ($uid == -1) { $this->errorCode = self::ERROR_USERNAME_INVALID; } elseif ($uid == -2) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } return !$this->errorCode; }
/** * 用户登录认证 * @param string $username 用户名 * @param string $password 用户密码 * @param integer $type 用户名类型 (1-用户名,2-邮箱,3-手机,4-UID) * @return integer 登录成功-用户ID,登录失败-错误编号 */ public function login($username, $password, $type = 1) { if (file_exists('./api/uc_login.lock')) { include_once './api/uc_client/client.php'; if (strtolower(UC_CHARSET) == 'gbk') { $username = iconv('UTF-8', 'GBK', $username); } $uc_user = uc_user_login($username, $password, 0); if ($uc_user[0] == -2) { return '密码错误'; } elseif ($uc_user[0] == -1) { return '用户不存在,或者被删除'; } elseif ($uc_user[0] > 0) { if (strtolower(UC_CHARSET) == 'gbk') { $uc_user[1] = iconv('GBK', 'UTF-8', $uc_user[1]); } D('member')->where(array('uid' => $uc_user[0]))->setField('nickname', $uc_user[1]); D('ucenter_member')->where(array('id' => $uc_user[0]))->setField('username', $uc_user[1]); return $uc_user[0]; } } else { if (UC_SYNC && $username != get_username(1)) { return $this->ucLogin($username, $password); } return $this->model->login($username, $password, $type); } }
function login($username, $password) { $tuser = $_ENV['user']->get_by_username($username); $ucenter_user = uc_get_user($username); if (!$ucenter_user && ($tuser['username'] == $username && $password == $tuser['password'])) { $uid = uc_user_register($tuser['username'], $this->base->post['password'], $tuser['email']); $this->db->query("UPDATE " . DB_TABLEPRE . "user SET uid={$uid} WHERE uid=" . $tuser['uid']); } //通过接口判断登录帐号的正确性,返回值为数组 list($uid, $username, $password, $email) = uc_user_login($username, $password); if ($uid > 0) { $user = $this->db->fetch_first("SELECT * FROM " . DB_TABLEPRE . "user WHERE uid='{$uid}'"); if (!$user) { $_ENV['user']->add($username, $password, $email, $uid); } if ($user['password'] != $password) { $this->db->query("UPDATE " . DB_TABLEPRE . "user SET password='******' WHERE uid={$uid}"); } $_ENV['user']->refresh($uid); //生成同步登录的代码 $ucsynlogin = uc_user_synlogin($uid); $this->base->message('登录成功!' . $ucsynlogin . '<br><a href="' . $_SERVER['PHP_SELF'] . '">继续</a>'); } elseif ($uid == -1) { $this->base->message('用户不存在,或者被删除!'); } elseif ($uid == -2) { $this->base->message('密码错误!'); } else { $this->base->message('未定义!'); } }
function userlogin($username, $password, $questionid, $answer, $loginfield = 'username') { $return = array(); if ($loginfield == 'uid') { $isuid = 1; } elseif ($loginfield == 'email') { $isuid = 2; } elseif ($loginfield == 'auto') { $isuid = 3; } else { $isuid = 0; } if (!function_exists('uc_user_login')) { loaducenter(); } if ($isuid == 3) { if (preg_match('/^[1-9]\\d*$/', $username)) { $return['ucresult'] = uc_user_login($username, $password, 1, 1, $questionid, $answer); } elseif (isemail($username)) { $return['ucresult'] = uc_user_login($username, $password, 2, 1, $questionid, $answer); } if ($return['ucresult'][0] <= 0) { $return['ucresult'] = uc_user_login($username, $password, 0, 1, $questionid, $answer); } } else { $return['ucresult'] = uc_user_login($username, $password, $isuid, 1, $questionid, $answer); } $tmp = array(); $duplicate = ''; list($tmp['uid'], $tmp['username'], $tmp['password'], $tmp['email'], $duplicate) = daddslashes($return['ucresult'], 1); $return['ucresult'] = $tmp; if ($duplicate && $return['ucresult']['uid'] > 0) { if ($olduid = DB::result_first("SELECT uid FROM " . DB::table('common_member') . " WHERE username='******'ucresult']['username']) . "'")) { require_once libfile('function/membermerge'); if ($olduid != $return['ucresult']['uid']) { membermerge($olduid, $return['ucresult']['uid']); } uc_user_merge_remove($return['ucresult']['username']); } else { $return['status'] = 0; return $return; } } if ($return['ucresult']['uid'] <= 0) { $return['status'] = 0; return $return; } $member = DB::fetch_first("SELECT * FROM " . DB::table('common_member') . " WHERE uid='" . $return['ucresult']['uid'] . "'"); if (!$member) { $return['status'] = -1; return $return; } $return['member'] = $member; $return['status'] = 1; if (addslashes($member['email']) != $return['ucresult']['email']) { DB::query("UPDATE " . DB::table('common_member') . " SET email='" . $return['ucresult']['email'] . "' WHERE uid='" . $return['ucresult']['uid'] . "'"); } return $return; }
/** * Check if the password is correct without logging in the user * * @param string $uid The username * @param string $password The password * * @return true/false */ public function checkPassword($uid, $password) { $result = uc_user_login($uid, $password); if ($result[0] > 0) { $this->storeUser($uid); return $uid; } else { return false; } }
function userlogin() { global $db, $tablepre, $_DCACHE, $ucresult, $username, $password, $questionid, $answer, $loginfield; require_once DISCUZ_ROOT . './uc_client/client.php'; if ($loginfield == 'uid') { $isuid = 1; } elseif ($loginfield == 'email') { $isuid = 2; } else { $isuid = 0; } $ucresult = uc_user_login($username, $password, $isuid, 1, $questionid, $answer); list($tmp['uid'], $tmp['username'], $tmp['password'], $tmp['email'], $duplicate) = daddslashes($ucresult, 1); $ucresult = $tmp; if ($duplicate && $ucresult['uid'] > 0) { if ($olduid = $db->result_first("SELECT uid FROM {$tablepre}members WHERE username='******'username']) . "'")) { require_once DISCUZ_ROOT . './include/membermerge.func.php'; membermerge($olduid, $ucresult['uid']); uc_user_merge_remove($ucresult['username']); } else { return 0; } } if ($ucresult['uid'] <= 0) { return 0; } $member = $db->fetch_first("SELECT m.uid AS discuz_uid, m.username AS discuz_user, m.password AS discuz_pw, m.secques AS discuz_secques,\r\n\t\tm.email, m.adminid, m.groupid, m.styleid, m.lastvisit, m.lastpost, u.allowinvisible\r\n\t\tFROM {$tablepre}members m LEFT JOIN {$tablepre}usergroups u USING (groupid)\r\n\t\tWHERE m.uid='{$ucresult['uid']}'"); if (!$member) { return -1; } $member['discuz_userss'] = $member['discuz_user']; $member['discuz_user'] = addslashes($member['discuz_user']); foreach ($member as $var => $value) { $GLOBALS[$var] = $value; } if (addslashes($member['email']) != $ucresult['email']) { $db->query("UPDATE {$tablepre}members SET email='{$ucresult['email']}' WHERE uid='{$ucresult['uid']}'"); } if ($questionid > 0 && empty($member['discuz_secques'])) { $GLOBALS['discuz_secques'] = random(8); $db->query("UPDATE {$tablepre}members SET secques='{$GLOBALS['discuz_secques']}' WHERE uid='{$ucresult['uid']}'"); } $GLOBALS['styleid'] = $member['styleid'] ? $member['styleid'] : $_DCACHE['settings']['styleid']; $cookietime = intval(isset($_POST['cookietime']) ? $_POST['cookietime'] : 0); dsetcookie('cookietime', $cookietime, 31536000); dsetcookie('auth', authcode("{$member['discuz_pw']}\t{$member['discuz_secques']}\t{$member['discuz_uid']}", 'ENCODE'), $cookietime, 1, true); dsetcookie('loginuser'); dsetcookie('activationauth'); dsetcookie('pmnum'); $GLOBALS['sessionexists'] = 0; if ($_DCACHE['settings']['frameon'] && $_DCOOKIE['frameon'] == 'yes') { $GLOBALS['extrahead'] .= '<script>if(top != self) {parent.leftmenu.location.reload();}</script>'; } return 1; }
function userlogin($username, $password, $questionid, $answer, $loginfield = 'username', $ip = '') { $return = array(); if($loginfield == 'uid' && getglobal('setting/uidlogin')) { $isuid = 1; } elseif($loginfield == 'email') { $isuid = 2; } elseif($loginfield == 'auto') { $isuid = 3; } else { $isuid = 0; } if(!function_exists('uc_user_login')) { loaducenter(); } if($isuid == 3) { if(!strcmp(dintval($username), $username) && getglobal('setting/uidlogin')) { $return['ucresult'] = uc_user_login($username, $password, 1, 1, $questionid, $answer, $ip); } elseif(isemail($username)) { $return['ucresult'] = uc_user_login($username, $password, 2, 1, $questionid, $answer, $ip); } if($return['ucresult'][0] <= 0 && $return['ucresult'][0] != -3) { $return['ucresult'] = uc_user_login(addslashes($username), $password, 0, 1, $questionid, $answer, $ip); } } else { $return['ucresult'] = uc_user_login(addslashes($username), $password, $isuid, 1, $questionid, $answer, $ip); } $tmp = array(); $duplicate = ''; list($tmp['uid'], $tmp['username'], $tmp['password'], $tmp['email'], $duplicate) = $return['ucresult']; $return['ucresult'] = $tmp; if($duplicate && $return['ucresult']['uid'] > 0 || $return['ucresult']['uid'] <= 0) { $return['status'] = 0; return $return; } $member = getuserbyuid($return['ucresult']['uid'], 1); if(!$member || empty($member['uid'])) { $return['status'] = -1; return $return; } $return['member'] = $member; $return['status'] = 1; if($member['_inarchive']) { C::t('common_member_archive')->move_to_master($member['uid']); } if($member['email'] != $return['ucresult']['email']) { C::t('common_member')->update($return['ucresult']['uid'], array('email' => $return['ucresult']['email'])); } return $return; }
public function dologin() { if ($this->user['id']) { $this->Redirect('', '', '', 1); } $url = $this->input['referto'] ? $this->input['referto'] : ""; $request_name = 'username'; $request_password = '******'; $request_email = 'email'; $user_name = addslashes($this->input[$request_name]); $password = addslashes($this->input[$request_password]); if (!$user_name && !$password) { $this->ReportError($this->lang['nameerror']); } $email = addslashes($this->input[$request_email]); $member = uc_user_login($user_name, $password); $timestamp = TIMENOW; // uid 大于0 登录成功,-1 : 用户不存在,或者被删除 -2:密码错误 其他:未定义 if ($member[0] > 0) { //同步登录 $ucsynlogin = uc_user_synlogin($member[0]); $user_name = $member[1]; $password = $member[4]; $user_id = $member[0]; $sql = "SELECT * FROM " . DB_PREFIX . "user WHERE username='******'"; $first = $this->db->query_first($sql); if (!$first) { include_once ROOT_PATH . 'lib/user/user.class.php'; $ucUser = new user(); $info = $ucUser->verify_user_exist($user_name, addslashes($this->input[$request_password])); $ip = hg_getip(); $sql = "INSERT INTO " . DB_PREFIX . "user(id,username,password,salt,email,avatar,register_time,ip) \r\n\t\t\t\tvalues(" . $info['id'] . ",'" . $info['username'] . "','" . $info['password'] . "','" . $info['salt'] . "','" . $info['email'] . "','" . $info['avatar'] . "'," . $info['join_time'] . ",'" . $ip . "')"; $this->db->query($sql); $id = $this->db->insert_id(); $sql = "INSERT INTO " . DB_PREFIX . "user_extra(user_id) \r\n\t\t\t\tvalues(" . $id . ")"; $this->db->query($sql); $user_name = $second['username']; $password = $second['password']; $user_id = $id; } //本地系统 hg_set_cookie('user', $user_name, $timestamp + 31536000); hg_set_cookie('pass', $password, $timestamp + 31536000); hg_set_cookie('userid', $user_id, $timestamp + 31536000); $this->Redirect($this->lang['loginsucess'], $url, 2, 0, $ucsynlogin); } else { $this->ReportError($this->lang['nameerror']); } }
/** * 会员登陆 * * @param string $username * @param string $password * @return array|string */ public function login($username, $password) { list($uid, $username, $password, $email) = uc_user_login($username, $password); if ($uid > 0) { return array('uid' => $uid, 'username' => $username, 'password' => $password, 'email' => $email); } elseif ($uid == -1) { return '用户不存在,或者被删除'; } elseif ($uid == -2) { return '密码错误'; } elseif ($uid == -3) { return '安全提问错误'; } else { return '未定义'; } }
function zuitu_uc_synlogin($email, $pass) { if (!function_exists('uc_user_login')) return array(); if (!defined('UC_API')) return array(); $isuid = strpos($email, '@') ? 2 : 0; if (strtolower(UC_CHARSET)!='utf-8') { $email = mb_convert_encoding($email, UC_CHARSET, 'UTF-8'); } $ucresult = uc_user_login($email, $pass, $isuid, 0); $uckey = array( 'uid', 'username', 'password', 'email', 'duplicate' ); $ucresult = array_combine($uckey, $ucresult); if ($ucresult['uid']>0 ) { $script_string = uc_user_synlogin($ucresult['uid']); Session::Set('script', $script_string); } DB::Query('SET NAMES UTF8;'); }
function API_Login($user, $pass) { global $db, $onlineip; include_once ONEZ_ROOT . './uc_client/client.php'; $api = uc_user_login($user, $pass, 0); list($uid, $username, $password, $email) = $api; if ($uid < 0) { if ($uid == -1) { return '用户不存在,或者被删除'; } elseif ($uid == -2) { return '用户名或密码不正确'; } elseif ($uid == -3) { return '安全提问错'; } } if (!$db) { include_once ONEZ_ROOT . './include/db_mysql.class.php'; db_local(); $db = new onez_db(); } $db->reset(); if ($db->rows("users", "uid='{$uid}'") == 0) { //创建本地用户 if ($data = uc_get_user($uid, 1)) { list($uid, $username, $email) = $data; $arr = array('uid' => $uid, 'username' => $username, 'password' => md5($pass), 'email' => $email, 'infoip' => $onlineip, 'infotime' => time()); $db->insert('users', $arr); } } $GLOBALS['cookiepre'] = 'onez_'; osetcookie('userid', $uid, 31536000); osetcookie('username', $username, 31536000); echo uc_user_synlogin($uid); echo <<<ONEZ <p align="center"><br /><br /><br /><br /> <a href="#" onclick="ReLoad()"><font size="2" color="#0000ff">正在同步登录中...</font></a> </p> <script type="text/javascript"> function ReLoad(){ top.location.reload(); } window.onload=ReLoad; </script> ONEZ; exit; return 'Y'; }
/** * 进行身份验证 * 请保证传参所用字符集和论坛字符集一致,否则请先自行转换再传参 * @param string $username * @param string $password * @param int $questionid * @param string $answer * @param boolen $isuid 使用UID验证么? * @return array * 第一个数组下标($return[0])若大于0,则表示验证成功的登录uid。否则为错误信息: * -1:UC用户不存在,或者被删除 * -2:密码错 * -3:安全提问错 * -4:用户没有在dz注册 * 第二个数组下标($return[1])若大于等于0,则表示验证成功的adminid; * 否则为-1,表示验证失败 */ function verify($username, $password, $questionid = '', $answer = '', $isuid = 0) { $return = array(0 => -1, 1 => -1); $ip = XWB_plugin::getIP(); /** * 校验用户输入错误密码的次数 */ $failedlogins = $this->db->fetch_first("select * from " . XWB_S_TBPRE . "failedlogins where `ip`='{$ip}'"); if ($failedlogins && $failedlogins['count'] >= 5) { $return[0] = -5; return $return; } /** * 校验用户输入的用户名和密码是否正确 */ if (true === UCENTER) { //加载Ucenter客户端文件 include_once ROOT_PATH . './api/uc_client/client.php'; $uc_result = uc_user_login($username, $password, $isuid, 0, $questionid, $answer); $ucuid = $uc_result[0]; if ($ucuid < 1) { $return[0] = $ucuid; return $return; } } $member = $this->db->fetch_first("SELECT `uid`, `password`, `nickname`, `username`, `role_type`, `salt` FROM " . XWB_S_TBPRE . "members WHERE `nickname`='{$username}'"); if ($member) { /** * 在记事狗系统中比对用户输入的密码 */ if ($member['password'] == jsg_member_password($password, $member['salt'])) { $return[0] = (int) $member['uid']; $return[1] = 'admin' == $member['role_type'] ? 1 : 0; } else { $return[0] = -2; /** * 更新密码输入错误的次数 */ if ($failedlogins) { $this->db->query("update " . XWB_S_TBPRE . "failedlogins set `count`='" . (max(1, (int) $failedlogins['count']) + 1) . "', `lastupdate`='" . time() . "' where `ip`='{$ip}'"); } else { $this->db->query("insert into " . XWB_S_TBPRE . "failedlogins (`ip`,`count`,`lastupdate`) values ('{$ip}','1','" . time() . "')"); } } } return $return; }
static function login($username, $password, $isuid = 0) { list($uid, $username, $password, $email) = uc_user_login($username, $password, $isuid); setcookie(self::$authPre . 'auth', '', -86400); if ($uid > 0) { self::$uid = $uid; self::$username = $username; self::$password = md5($password); self::$email = $email; setcookie(self::$authPre . 'auth', uc_authcode($uid . "\t" . $username . "\t" . md5($password) . "\t" . $email, 'ENCODE')); return array('uid' => $uid, 'username' => $username, 'password' => $password, 'email' => $email, 'synlogin' => uc_user_synlogin($uid)); } else { self::$lastAction = 'login'; self::$lastErrorCode = $uid; return FALSE; } }
/** * Authenticates a user. * The example implementation makes sure if the username and password * are both 'demo'. * In practical applications, this should be changed to authenticate * against some persistent user identity storage (e.g. database). * @return boolean whether authentication succeeds. */ public function authenticate() { //Ucenter 登录 Yii::import('application.vendor.*'); require_once 'ucenter.php'; list($uid, $username, $password, $email) = uc_user_login($this->username, $this->password); if ($uid > 0) { $this->errorCode = self::ERROR_NONE; } elseif ($uid == -1) { $this->errorCode = self::ERROR_USERNAME_INVALID; } elseif ($uid == -2) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { $this->errorCode = self::ERROR_UNKNOWN_IDENTITY; } return !$this->errorCode; }
/** * 进行身份验证 * 请保证传参所用字符集和论坛字符集一致,否则请先自行转换再传参 * @param string $username * @param string $password * @param int $questionid * @param string $answer * @param boolen $isuid 使用UID验证么? * @return array * 第一个数组下标($return[0])若大于0,则表示验证成功的登录uid。否则为错误信息: * -1:UC用户不存在,或者被删除 * -2:密码错 * -3:安全提问错 * -4:用户没有在dz注册 * 第二个数组下标($return[1])若大于等于0,则表示验证成功的adminid; * 否则为-1,表示验证失败 */ function verify($username, $password, $questionid = '', $answer = '', $isuid = 0) { $return = array(0 => -1, 1 => -1); loaducenter(); $ucresult = uc_user_login($username, $password, $isuid, 1, $questionid, $answer); if ($ucresult[0] < 1) { $return[0] = $ucresult[0]; } else { $uid = (int) $ucresult[0]; $member = $this->db->fetch_first("SELECT uid, username, adminid\n\t\t\t\t\t\t\t\t\t\t\t\tFROM " . DB::table('common_member') . " \n\t\t\t\t\t\t\t\t\t\t\t\tWHERE uid='{$uid}'"); if (!$member) { $return[0] = -4; } else { $return[0] = (int) $member['uid']; $return[1] = (int) $member['adminid']; } } return $return; }
public function login() { $user = trim($_REQUEST['username']); if (UC_START == 'on') { @(include dirname(__FILE__) . '/../../config.inc.php'); if (UC_KEY == "" || UC_API == "") { exit("登陆失败,请检查uc配置文件config.inc.php"); } include dirname(__FILE__) . '/../../include/db_mysql.class.php'; include dirname(__FILE__) . '/../../uc_client/client.php'; list($uid, $username, $password, $email) = uc_user_login($user, $_REQUEST['passwd']); if ($uid > 0) { registerRole('user', $user); $_SESSION["uc_uid"] = $uid; header("Location: ?c=user&a=index&uc=1"); die; //$ucsynlogin = uc_user_synlogin($uid); //$this->assign('ucsynclogin',$ucsynlogin); //return dispatch('user','index'); //return $this->_tpl->fetch('user/index.html'); } else { header('Location: ?c=session&a=error'); die; } } else { if (!$this->checkRight($user)) { exit("用户名不符合标准"); } $userinfo = $this->checkPassword($user, $_REQUEST['passwd']); if (!$userinfo) { return $this->error(); } registerRole('user', $userinfo['username']); if ($GLOBALS['frame'] == 1) { header("Location: ?c=frame&a=index"); die; } else { header("Location: ?c=user&a=index"); die; } } }
public function login() { $user_info = $this->session->userdata('user'); if (!empty($user_info['username'])) { exit($user_info['username'] . ' You are logged in, <a href="logout">Logout</a>'); } if (empty($_POST['submit'])) { //登录表单 echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">'; echo 'login:'******'<dl><dt>Username</dt><dd><input name="username"></dd>'; echo '<dt>Password</dt><dd><input name="password" type="password"></dd></dl>'; echo '<input name="submit" type="submit"> '; echo '</form>'; exit; } else { //通过接口判断登录帐号的正确性,返回值为数组 list($uid, $username, $password, $email) = uc_user_login($_POST['username'], $_POST['password']); $this->session->sess_destroy(); if ($uid > 0) { $sql = 'SELECT count(*) FROM example_members WHERE uid="?"'; $query = $this->db->query($sql, $uid); if (!$query->num_rows()) { //判断用户是否存在于用户表,不存在则跳转到激活页面 $auth = rawurlencode(uc_authcode("{$username}\t" . time(), 'ENCODE')); echo 'You need to activate the account, to access this application<br><a href="register?action=activation&auth=' . $auth . '">继续</a>'; exit; } $this->session->set_userdata('user', array('username' => uc_authcode($uid . "\t" . $username, 'ENCODE'))); //生成同步登录的代码 $ucsynlogin = uc_user_synlogin($uid); echo 'Login successfully!' . $ucsynlogin . '<br><a href="login">continue</a>'; exit; } elseif ($uid == -1) { echo 'user not exists'; } elseif ($uid == -2) { echo 'password error'; } else { echo 'undefined'; } } }
function login($username, $password) { //通过接口判断登录帐号的正确性,返回值为数组 list($uid, $username, $password, $email) = uc_user_login($username, $password); if ($uid > 0) { if (!$this->db->result_first("SELECT count(*) FROM " . DB_TABLEPRE . "user WHERE uid='{$uid}'")) { $_ENV['user']->add($username, $password, $email, $uid); } $_ENV['user']->refresh($uid); //生成同步登录的代码 $ucsynlogin = uc_user_synlogin($uid); $this->base->message('登录成功' . $ucsynlogin . '<br><a href="' . $_SERVER['PHP_SELF'] . '">继续</a>'); } elseif ($uid == -1) { $this->base->message('用户不存在,或者被删除'); } elseif ($uid == -2) { $this->base->message('密码错误'); } else { $this->base->message('未定义'); } }
function login($username, $password, $type = 'g') { if (empty($username) || empty($password)) { return false; } $rt = uc_user_login($username . '#' . $type, $password); $uid = $rt[0]; if ($uid > 0) { return uc_user_synlogin($uid); } switch ($uid) { case -1: $return = array('result' => $uid, 'message' => 'user is not exist!!'); break; case -2: $return = array('result' => $uid, 'message' => 'wrong password!!'); break; } return $return; }
/** * $l {1:uid,2:email,0:uname} */ public function login($uname, $passwd, $l = 0) { list($m['uid'], $m['uname'], $m['passwd'], $m['mail']) = uc_user_login($this->iconv($uname), $passwd, (int) $l); $m['uname'] = $uname; return $m; if ($m['uid'] > 0) { $m['uname'] = $uname; return $m; } else { if ($m['uid'] == -1) { $this->err->add('用户不存在,或者被删除', 421); } else { if ($m['uid'] == -2) { $this->err->add('登录不正确', 422); } else { $this->err->add('未定义操作', 423); } } } return false; }
public function create() { $userInfo = array('email' => $this->input['email'], 'username' => $this->input['username'], 'password' => $this->input['password']); $ret = $this->info->createUser($userInfo); $user_name = addslashes($this->input['username']); $password = addslashes($this->input['password']); $email = addslashes($this->input['email']); include_once './uclient/client.php'; $member = uc_user_login($user_name, $password); // uid 大于0 登录成功,-1 : 用户不存在,或者被删除 -2:密码错误 其他:未定义 if ($member[0] > 0) { //同步登录 $ucsynlogin = uc_user_synlogin($member[0]); hg_set_cookie('user', $member[1], $timestamp + 31536000); hg_set_cookie('pass', $member[4], $timestamp + 31536000); hg_set_cookie('member_id', $member[0], $timestamp + 31536000); $ret['script'] = $ucsynlogin; } else { $this->ReportError($this->lang['nameerror']); } echo json_encode($ret); }
function login() { if ($this->user->isLogged()) { //用户已登陆,则不显示登录界面 redirect(); } if ($this->input->post('username')) { $user = array(); if ($this->company->ucenter) { $ucenter_user = uc_user_login($this->input->post('username'), $this->input->post('password')); //ucenter验证密码 if (!$ucenter_user) { $this->load->addViewData('warning', '用户名或密码错'); } elseif ($ucenter_user[0] > 0) { $user = $this->user->fetch($ucenter_user[0]); } } else { $user = $this->user->verify($this->input->post('username'), $this->input->post('password')); } if ($user) { $this->session->set_userdata('user/id', intval($user['id'])); $this->user->__construct($user['id']); $this->user->updateLoginTime(); if (!$this->company->ucenter && !isset($user['password'])) { redirect('#user/profile'); } elseif (!$this->company->ucenter) { redirect(); } else { redirect('', 'js'); } } else { $this->load->addViewData('warning', '用户名或密码错'); } } $this->load->view('head_simple'); $this->load->view('user/login'); $this->load->view('foot'); }
/** * Authenticates a user. * The example implementation makes sure if the username and password * are both 'demo'. * In practical applications, this should be changed to authenticate * against some persistent user identity storage (e.g. database). * @return boolean whether authentication succeeds. */ public function authenticate($oauth = false) { global $sysSettings; if (isset($sysSettings['partner']['mode']) && $sysSettings['partner']['mode'] == 'ucenter') { Yii::import('ext.ucenter.MUcenter', true); list($ucenterId, $username, $password, $email) = uc_user_login($this->username, $this->password, 2); $this->_authenticate($oauth); if ($ucenterId > 0 && $this->errorCode == self::ERROR_USERNAME_INVALID) { //说明网站数据库中没有,而ucenter中有这个用户,添加用户 User::model()->addUser($email, $password, array('name' => $username, 'bio' => ' ', 'status' => 'ok')); $this->errorCode = self::ERROR_NONE; } else { if ($ucenterId > 0 && $this->errorCode == self::ERROR_PASSWORD_INVALID) { $this->errorCode = self::ERROR_NONE; } else { if ($ucenterId == -1 && $this->errorCode == self::ERROR_NONE) { uc_user_register($this->userInfo->name, $this->password, $this->userInfo->email); } } } $this->setState('ucenterId', $ucenterId); } else { $this->_authenticate($oauth); } if ($this->errorCode == self::ERROR_NONE) { $userInfo = $this->userInfo; $userInfo->upTime = time(); $userInfo->save(); //动态设为超级用户 if ($userInfo->isAdmin) { Yii::app()->user->setIsSuperuser(true); } $this->_id = $userInfo->id; //用setState添加的变量会加入Yii::app()->user的属性中 $this->setState('displayName', $userInfo->name); } return !$this->errorCode; }
public static function login($name, $password, $expire = 0) { if ($expire > 0) { $expire = time() + $expire * 3600 * 24; } $name = strtolower($name); if (strlen($name) > 50 || strlen($password) > 20) { return false; } //尝试使用ucenter接口登录 list($uid, $uname, $upassword, $uemail) = uc_user_login($name, $password); //ucenter 接口登录成功! if ($uid > 0) { echo uc_user_synlogin($uid); if (is_null(self::login_by_uid($uid, $password, $expire))) { //本地用户库中不存在,插入用户数据 self::register($name, $uemail, $password, $uid); return self::login_by_uid($uid, $password, $expire); } } //ucenter 接口登录失败,尝试从本地用户库登录 $old_pwd = $password; $password = md5($password); $db = get_db(); $db->query("select id,uid from " . self::$s_table_name . " where (name='{$name}' or email='{$name}') and password='******'"); if ($db->record_count <= 0) { return false; } $user_id = $db->field_by_name('id'); $uid = $db->field_by_name('uid'); $cache_name = rand_str(20); if (self::_login($user_id, $uid, $name, $cache_name, $expire, $old_pwd) === false) { return false; } echo uc_user_synlogin($uid); return self::find($user_id); }
function login($_username, $_password) { if (H::valid_email($_username)) { // 使用 E-mail 登录 list($uc_uid, $username, $password, $email) = uc_user_login($_username, $_password, 2); } if ($this->ucenter_charset != 'utf-8') { $username = convert_encoding($username, $this->ucenter_charset, 'UTF-8'); } if (!$uc_uid) { if ($this->ucenter_charset != 'utf-8') { list($uc_uid, $username, $password, $email) = uc_user_login(convert_encoding($_username, 'utf-8', $this->ucenter_charset), $_password); if ($username) { $username = convert_encoding($username, $this->ucenter_charset, 'UTF-8'); } } else { list($uc_uid, $username, $password, $email) = uc_user_login($_username, $_password); } } if ($username) { $username = htmlspecialchars($username); } if ($uc_uid > 0) { if (!($user_info = $this->get_uc_user_info($uc_uid))) { if ($site_user_info = $this->model('account')->get_user_info_by_email($email)) { $this->insert('users_ucenter', array('uid' => $site_user_info['uid'], 'uc_uid' => $uc_uid, 'username' => $username, 'email' => $email)); return false; } if ($new_user_id = $this->model('account')->user_register($username, $_password, $email, TRUE)) { if ($exists_uc_id = $this->is_uc_user($email)) { $this->update('users_ucenter', array('username' => $username, 'uid' => $new_user_id), 'uc_uid = ' . intval($exists_uc_id)); } else { $this->insert('users_ucenter', array('uid' => $new_user_id, 'uc_uid' => $uc_uid, 'username' => $username, 'email' => $email)); if (uc_check_avatar($uc_uid, 'big')) { $avatar = @file_get_contents(UC_API . '/avatar.php?uid=' . $uc_uid . '&size=big'); if ($avatar) { AWS_APP::upload()->initialize(array('allowed_types' => 'jpg,jpeg,png,gif', 'upload_path' => get_setting('upload_dir') . '/avatar/' . $this->model('account')->get_avatar($new_user_id, '', 1), 'is_image' => TRUE, 'max_size' => get_setting('upload_avatar_size_limit'), 'file_name' => $this->model('account')->get_avatar($new_user_id, '', 2), 'encrypt_name' => FALSE))->do_upload('aws_upload_file', $avatar); if (!AWS_APP::upload()->get_error()) { $upload_data = AWS_APP::upload()->data(); if ($upload_data) { if ($upload_data['is_image'] == 1) { foreach (AWS_APP::config()->get('image')->avatar_thumbnail as $key => $val) { $thumb_file[$key] = $upload_data['file_path'] . $this->model('account')->get_avatar($new_user_id, $key, 2); AWS_APP::image()->initialize(array('quality' => 90, 'source_image' => $upload_data['full_path'], 'new_image' => $thumb_file[$key], 'width' => $val['w'], 'height' => $val['h']))->resize(); } } $update_data['avatar_file'] = $this->model('account')->get_avatar($new_user_id, null, 1) . basename($thumb_file['min']); // 更新主表 $this->model('account')->update_users_fields($update_data, $new_user_id); if (!$this->model('integral')->fetch_log($new_user_id, 'UPLOAD_AVATAR')) { $this->model('integral')->process($new_user_id, 'UPLOAD_AVATAR', round(get_setting('integral_system_config_profile') * 0.2), '上传头像'); } } } } } } $user_info = $this->model('account')->get_user_info_by_uid($new_user_id, true, false); } } else { // Update password $this->model('account')->update_user_password_ingore_oldpassword($_password, $user_info['uid'], $user_info['salt']); // Update username if ($user_info['user_name'] != $username) { if (!$this->model('account')->check_username($username)) { $this->model('account')->update_user_name($username, $user_info['uid']); $this->update('users_ucenter', array('username' => htmlspecialchars($username)), 'uc_uid = ' . intval($uc_uid)); } } } } return $user_info; }
} else { if (!$outexange && !$extcredits[$tocredits]['ratio']) { showmessage('credits_exchange_invalid'); } $amount = intval($amount); if ($outexange) { $netamount = floor($amount * $outextcredits[$tocredits]['ratiosrc'][$fromcredits] / $outextcredits[$tocredits]['ratiodesc'][$fromcredits]); } else { if ($extcredits[$tocredits]['ratio'] < $extcredits[$fromcredits]['ratio']) { $netamount = ceil($amount * $extcredits[$tocredits]['ratio'] / $extcredits[$fromcredits]['ratio'] * (1 + $creditstax)); } else { $netamount = floor($amount * $extcredits[$tocredits]['ratio'] / $extcredits[$fromcredits]['ratio'] * (1 + $creditstax)); } } require_once DISCUZ_ROOT . './uc_client/client.php'; $ucresult = uc_user_login($discuz_user, $password); list($tmp['uid']) = daddslashes($ucresult); if ($tmp['uid'] <= 0) { showmessage('credits_password_invalid'); } elseif ($fromcredits == $tocredits) { showmessage('credits_exchange_invalid'); } elseif ($amount <= 0) { showmessage('credits_transaction_amount_invalid'); } elseif (${'extcredits' . $fromcredits} - $netamount < ($minbalance = $exchangemincredits)) { showmessage('credits_balance_insufficient'); } elseif (!$outexange && !$netamount) { showmessage('credits_net_amount_iszero'); } if (!$outexange && !$extcredits[$fromcredits]['allowexchangeout']) { showmessage('extcredits_disallowexchangeout'); }
if (!defined('IN_DISCUZ')) { exit('Access Denied'); } define('IN_MODCP', true); if (!empty($_G['forum']) && $_G['forum']['status'] == 3) { showmessage('group_admin_enter_panel', 'forum.php?mod=group&action=manage&fid=' . $_G['fid']); } require_once DISCUZ_ROOT . './source/admincp/admincp_cpanel.php'; $_G['gp_action'] = empty($_G['gp_action']) && $_G['fid'] ? 'thread' : $_G['gp_action']; $op = getgpc('op'); $cpscript = basename($_G['PHP_SELF']); $modsession = new AdminSession($_G['uid'], $_G['groupid'], $_G['adminid'], $_G['clientip']); if ($modsession->cpaccess == 1) { if ($_G['gp_action'] == 'login' && $_G['gp_cppwd'] && submitcheck('submit')) { loaducenter(); $ucresult = uc_user_login($_G['uid'], $_G['gp_cppwd'], 1); if ($ucresult[0] > 0) { $modsession->errorcount = '-1'; $url_forward = $modsession->get('url_forward'); $modsession->clear(true); $url_forward && dheader("Location: {$cpscript}?mod=modcp&{$url_forward}"); $_G['gp_action'] = 'home'; } else { $modsession->errorcount++; $modsession->update(); } } else { $_G['gp_action'] = 'login'; } } if ($_G['gp_action'] == 'logout') {
/** * UC登录或者注册 * @param string $username * @param string $password * @param string $is_remember_me 是否记住登录 * @return bool */ private function ucLogin($username, $password, $is_remember_me) { //载入UC客户端SDK include_once SITE_PATH . '/api/uc_client/client.php'; //1. 获取UC信息. if ($this->isValidEmail($username)) { $use_email = true; $uc_login_type = 2; } else { $use_email = false; $uc_login_type = 0; } $uc_user = uc_user_login($username, $password, $uc_login_type); //2. 已经同步过的直接登录 $uc_user_ref = ts_get_ucenter_user_ref('', $uc_user['0'], ''); if ($uc_user_ref['uid'] && $uc_user_ref['uc_uid'] && $uc_user[0] > 0) { //登录本地帐号 $result = $uc_user_ref['uid'] > 0 ? $this->_recordLogin($uc_user_ref['uid'], $is_remember_me) : false; if ($result) { $this->success .= uc_user_synlogin($uc_user[0]); return true; } else { $this->error = '登录失败,请重试'; return false; } } //3. 关联表无、获取本地帐号信息. $ts_user = $this->getLocalUser($username, $password); // 调试用-写log // $log_message = "============================ \n " // .date('Y-m-d H:i:s')." \n ".$_SERVER['REQUEST_URI']." \n " // .var_export($uc_user,true)." \n " // .var_export($ts_user,true)." \n " // .var_export($uc_user_ref,true)." \n "; // $log_file = SITE_PATH."/ts_uc_log.txt"; // $result = error_log($log_message,3,$log_file); //4. 关联表无、UC有、本地有的 if ($uc_user[0] > 0 && $ts_user['uid'] > 0) { $result = ts_add_ucenter_user_ref($ts_user['uid'], $uc_user[0], $uc_user[1], $uc_user[3]); if (!$result) { $this->error = '用户不存在或密码错误'; return false; } //登录本地帐号 $result = $this->_recordLogin($ts_user['uid'], $is_remember_me); if ($result) { $this->success .= uc_user_synlogin($uc_user[0]); return true; } else { $this->error = '登录失败,请重试'; return false; } } //5. 关联表无、UC有、本地无的 if ($uc_user[0] > 0 && !$ts_user['uid']) { //写入本地系统 $login_salt = rand(11111, 99999); $map['uname'] = $uc_user[1]; $map['sex'] = 1; $map['login_salt'] = $login_salt; $map['password'] = md5(md5($uc_user[2]) . $login_salt); $map['login'] = $map['email'] = $uc_user[3]; $map['reg_ip'] = get_client_ip(); $map['ctime'] = time(); $map['is_audit'] = 1; $map['is_active'] = 1; $map['first_letter'] = getFirstLetter($uname); //如果包含中文将中文翻译成拼音 if (preg_match('/[\\x7f-\\xff]+/', $map['uname'])) { //昵称和呢称拼音保存到搜索字段 $map['search_key'] = $map['uname'] . ' ' . model('PinYin')->Pinyin($map['uname']); } else { $map['search_key'] = $map['uname']; } $ts_uid = model('User')->add($map); if (!$ts_uid) { $this->error = '本地用户注册失败,请联系管理员'; return false; } //写入关联表 $result = ts_add_ucenter_user_ref($ts_uid, $uc_user[0], $uc_user[1], $uc_user[3]); if (!$result) { $this->error = '用户不存在或密码错误'; return false; } // 添加至默认的用户组 $registerConfig = model('Xdata')->get('admin_Config:register'); $userGroup = empty($registerConfig['default_user_group']) ? C('DEFAULT_GROUP_ID') : $registerConfig['default_user_group']; model('UserGroupLink')->domoveUsergroup($ts_uid, implode(',', $userGroup)); // 添加双向关注用户 $eachFollow = $registerConfig['each_follow']; if (!empty($eachFollow)) { model('Follow')->eachDoFollow($ts_uid, $eachFollow); } // 添加默认关注用户 $defaultFollow = $registerConfig['default_follow']; $defaultFollow = array_diff(explode(',', $defaultFollow), explode(',', $eachFollow)); if (!empty($defaultFollow)) { model('Follow')->bulkDoFollow($ts_uid, $defaultFollow); } //登录本地帐号 $result = $this->_recordLogin($ts_uid, $is_remember_me); if ($result) { $this->success .= uc_user_synlogin($uc_user[0]); return true; } else { $this->error = '登录失败,请重试'; return false; } } //6. 关联表无、UC无、本地有 if ($uc_user[0] < 0 && $ts_user['uid'] > 0) { //写入UC $uc_uid = uc_user_register($ts_user['uname'], $password, $ts_user['email'], '', '', get_client_ip()); if ($uc_uid > 0) { $this->error = 'UC帐号注册失败,请联系管理员'; return false; } //写入关联表 $result = ts_add_ucenter_user_ref($ts_user['uid'], $uc_uid, $ts_user['uname'], $ts_user['email']); if (!$result) { $this->error = '用户不存在或密码错误'; return false; } //登录本地帐号 $result = $this->_recordLogin($ts_user['uid'], $is_remember_me); if ($result) { $this->success .= uc_user_synlogin($uc_uid); return true; } else { $this->error = '登录失败,请重试'; return false; } } //7. 关联表无、UC无、本地无的 $this->error = '用户不存在'; return false; }