Skip to content

Instantly share code, notes, and snippets.

@langyo
Created April 25, 2023 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save langyo/0856934d1405801597514ba023de84ea to your computer and use it in GitHub Desktop.
Save langyo/0856934d1405801597514ba023de84ea to your computer and use it in GitHub Desktop.
discuz x2 的鉴权密码算法
<?php
# 来自 https://github.com/langyo/docker_discuz_x2/blob/main/upload/uc_client/model/user.php
# 行 119 - 139
function check_login($username, $password, &$user) {
$user = $this->get_user_by_username($username);
if(empty($user['username'])) {
return -1;
} elseif($user['password'] != md5(md5($password).$user['salt'])) {
return -2;
}
return $user['uid'];
}
function add_user($username, $password, $email, $uid = 0, $questionid = '', $answer = '', $regip = '') {
$regip = empty($regip) ? $this->base->onlineip : $regip;
$salt = substr(uniqid(rand()), -6);
$password = md5(md5($password).$salt);
$sqladd = $uid ? "uid='".intval($uid)."'," : '';
$sqladd .= $questionid > 0 ? " secques='".$this->quescrypt($questionid, $answer)."'," : " secques='',";
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."members SET $sqladd username='$username', password='$password', email='$email', regip='$regip', regdate='".$this->base->time."', salt='$salt'");
$uid = $this->db->insert_id();
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."memberfields SET uid='$uid'");
return $uid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment