Onex ecstore商城会员密码操作
Ecstore商城会员密码操作实现如下:
==============会员注册密码加密方式==============================
//
$accountData['login_password'] //会员登录密码
$use_pass_data['login_name'] = $password_account; //会员登录账号
$use_pass_data['createtime'] = time();
$login_password = pam_encrypt::get_encrypted_password(trim($accountData['login_password']),'member',$use_pass_data);
/**
* 得到自定义加密方式的密文
* @param string $password 密码明文
* @param string $account_type 加密类型,对应的类文件
* @return string 返回加密后的密文
*/
public static function get_encrypted_password($password,$account_type,$userdata=null){
$encrypt = kernel::service('encrypt_'.$account_type);
if(is_object($encrypt) && $userdata){
if(method_exists($encrypt,'get_encrypted')){
}
}else{
$encrypt = kernel::single('pam_encrypt_default');
}
return $encrypt->get_encrypted($password,$account_type,$userdata);
}
/**
* 获取加密类型后的密文
* @param string $source_str 用户的密码
* @return string 返回加密密文
*/
public function get_encrypted($source_str,$account_type,$userdata=null)
{
if(!$userdata) return md5($source_str);
if($userdata['createtime'])
{
return $this->extends_md5($source_str,$userdata['login_name'],$userdata['createtime']);
} else{
$pam_account_model = app::get('pam')->model('account');
$pam_filter = array(
'login_name'=>$userdata['login_name'],
'account_type' => $account_type,
'disabled' => 'false',
);
$rows = $pam_account_model->getList('*',$pam_filter,0,1);
if($rows[0]) {
if(substr($rows[0]['login_password'],0,1) !== 's') {
return md5($source_str);
} else{
return $this->extends_md5($source_str,$userdata['login_name'],$rows[0]['createtime']);
}
}else{
return false;
}
}
}
/**
* 会员密码加密方式
* @param string $source_str 用户的密码
* @return end_string 返回加密密文
*/
public function extends_md5($source_str,$username,$createtime)
{
$string_md5 = md5(md5($source_str).$username.$createtime);
$front_string = substr($string_md5,0,31);
$end_string = 's'.$front_string;
return $end_string;
}
$userPassport = kernel::single('b2c_user_passport');
$_POST['newPassword']:新密码
$_POST['confirmPassword']:确认密码
$member_id :会员ID
//开启事务
$this->begin();
if ( !$userPassport->check_passport($_POST['newPassword'],$_POST['confirmPassword'],$msg) ){
$this->end(false,$msg);
}
if ( !$userPassport->reset_passport($member_id,trim($_POST['newPassword'])) ){
$msg=app::get('b2c')->_('密码修改失败!');
$this->end(false,$msg);
}else{
$rs = true;
$msg = '密码修改成功';
$url = 'index.php?app=cps&ctl=admin_users&act=index';
//页面跳转
$this->end($rs, $msg, $url);
}
/*
* 根据会员ID 修改用户密码
*$password 要修改的密码
**/
public function reset_passport($member_id,$password){
$pamObj = app::get('pam')->model('members');
#获取会员所有的登录方式
$pamData = $pamObj->getList('login_account,password_account,createtime',array('member_id'=>$member_id));
$db = kernel::database();
$db->beginTransaction();
foreach($pamData as $row){
$use_pass_data['login_name'] = $row['password_account'];
$use_pass_data['createtime'] = $row['createtime'];
$login_password = pam_encrypt::get_encrypted_password(trim($password),'member',$use_pass_data);
$u_status=$pamObj->update(array('login_password'=>$login_password),array('login_account'=>$row['login_account']));
if($u_status){
$db->rollBack();
return false;
}
}
$db->commit();
return true;
}