~~~
<?php
/**
* 找回密碼_步驟
** 判斷帳號類型
** 手機發送驗證碼||郵箱發送驗證碼
** 修改密碼
**/
public function findpass()
{
$step = I('get.step');
if($step == 1 || $step == null || !$step){ //step1
if(IS_POST){
$account = I('post.account') ? trim(I('post.account')) : '';
if(!$account) $this->error('帳號不能為空!');
$M = M('member');
//驗證帳號是否存在
$Account = $M->field('mtel,email')->where(" mtel = '$account' or email = '$account' ")->select();
if(!$Account) $this->error('賬戶未注冊');
$this->assign('account',$account);
$type = 0; //賬號類型:0空,1手機,-1郵箱
//分辨帳號類型
if(preg_match('/^1[3456789]\d{9}$/',$account)) $type = 1;
if(preg_match('/^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/',$account)) $type = -1;
//跳轉步驟二
$this->assign('type',$type);
$this->step = 2;
$this->display();
}else{ //!IS_POST
$this->step = 1;
$this->display();
}
}elseif($step == 2 ){ //step2
if(IS_POST){
$account = I('post.account') ? trim(I('post.account')) : '';
$code = I('post.code') ? trim(I('post.code')) : '';
if(!$code) $this->error('驗證碼不能為空!');
if(!$account) $this->error('帳號不能為空!');
if($scode = authcode(cookie('code'),'DECODE')){
$scode = explode('#',$scode);
if($scode[2] != $account) $this->error('驗證碼無效!');
if(time() - $scode[1] > 5*60) $this->error('驗證碼已過期!');
if($scode[0] != $code) $this->error('驗證碼錯誤!');
//跳轉步驟三
$this->assign('account',$account);
$this->step = 3;
$this->display();
}else $this->error('驗證碼無效!');
}else{ //!IS_POST
$this->error('非法操作!');
}
}elseif($step == 3 ){ //step3
if(IS_POST){
$account = I('post.account') ? trim(I('post.account')) : '';
$orgpass = I('post.orgpass') ? trim(I('post.orgpass')) : '';
$compass = I('post.compass') ? trim(I('post.compass')) : '';
if(!$account) $this->error('帳號不能為空!');
if(!$orgpass) $this->error('不能設置空密碼!');
if(!$compass) $this->error('確認密碼不能為空!');
if($compass != $orgpass) $this->error('密碼不一致!');
$M = M('member');
$oldpass = $M->field('password,mid')->where(" mtel = '$account' or email = '$account' ")->find();
$data['password'] = md5($compass);
$data['mid'] = $oldpass['mid'];
if($data['password'] == $oldpass['password']) $this->error('舊密碼與新密碼一致');
if($M->save($data) !== false){
$this->success('修改密碼成功','Index/index');
}else $this->error('修改密碼失敗');
}else{ //!IS_POST
$this->error('非法操作!');
}
}else $this->error('非法操作!');
}
public function sendVeifyCode()
{
$account = I('post.account') ? trim(I('post.account')) : '';
if(!$account) $this->error('帳號不能為空!');
$yzm = I('post.yzm') ? trim(I('post.yzm')) : '';
$captcha = cookie('captcha');
//驗證碼檢測
if(!$yzm || !$captcha) $this->error('驗證碼不能為空!');
$captcha = authcode(cookie('captcha'),'DECODE');
$captchaArr = explode('#',$captcha);
if(count($captchaArr) != 2 || $captchaArr[0] != $yzm) $this->error('驗證碼錯誤!');
if($captchaArr[1] < time() - 60*5) $this->error('驗證碼超時!');
//分辨帳號類型
$type = 0; //賬號類型:0空,1手機,-1郵箱
if(preg_match('/^1[3456789]\d{9}$/',$account)) $type = 1;
if(preg_match('/^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/',$account)) $type = -1;
//賬號是否存在
$M = M('member');
if($type > 0){ //手機
//發送短信驗證
(sendCode($account,$yzm))?$this->success('手機驗證碼發送成功!'):$this->error('手機驗證碼發送失敗!');
}elseif($type < 0){ //郵箱
//發送郵箱驗證
$title = "找回密碼(系統郵件,請勿回復)";
$code = rand(100000,999999);
$content = "<div id='qm_con_body'><div id='mailContentContainer' class='qmbox qm_con_body_content qqmail_webmail_only' style=''><table style='font-size:14px; font-family:Arial, Helvetica, sans-serif; line-height:170%;' width='100%' cellspacing='0' cellpadding='0' border='0'><tbody><tr><td><p align='left'>親愛的用戶<strong>".$this->userinfo[mname]."</strong>,您好: </p><p align='left'> 驗證碼</p><p align='left'> <u>".$code."</u></p><p align='left'>有效期為5分鐘。如非本人操作,請忽略本郵件。</p></td></tr></tbody></table><br><hr><br>這只是一封系統自動發出的郵件,請不要直接回復。<style type='text/css'>.qmbox style, .qmbox script, .qmbox head, .qmbox link, .qmbox meta {display: none !important;}</style></div></div>";
if(sendMail($account,$title,$content)){
$code = authcode($code.'#'.time().'#'.$account, 'ENCODE');
cookie('captcha',null);
cookie('code',$code);
$this->success('郵箱驗證碼發送成功!');
}else $this->error('郵箱驗證碼發送失敗!');
}
}
function sendCode($phone,$yzm){
$captcha = cookie('captcha');
if(!$phone) return '手機號碼不能為空';
if(!preg_match('/^1[3456789]\d{9}$/',$phone)) return '手機號碼格式不正確';
if(!$yzm) return '驗證碼不能為空';
$captcha = authcode(cookie('captcha'),'DECODE');
$captchaArr = explode('#',$captcha);
if(count($captchaArr) != 2 || $captchaArr[0] != $yzm) return '驗證碼錯誤';
if($captchaArr[1] < time() - 60*5) return '驗證碼超時';
$code = rand(100000,999999);
$con = file_get_contents('http://domain.com/api/GetCode.php?tel='.$phone.'&code='.$code);
if($con == '100'){
$code = authcode($code.'#'.time().'#'.$phone, 'ENCODE');
cookie('captcha',null);
cookie('code',$code);
return true;
}else return '發送失敗';
}
function sendMail($to, $title, $content) {
Vendor('PHPMailer.PHPMailerAutoload');
$mail = new PHPMailer(); //實例化
$mail->IsSMTP(); // 啟用SMTP
$mail->Host=C('MAIL_HOST'); //smtp服務器的名稱
$mail->Port = C('SMTP_PORT'); //郵件發送端口
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = C('MAIL_SMTPAUTH'); //啟用smtp認證
$mail->Username = C('MAIL_USERNAME'); //發件人郵箱名
$mail->Password = C('MAIL_PASSWORD') ; //郵箱密碼
$mail->From = C('MAIL_FROM'); //發件人地址
$mail->FromName = C('MAIL_FROMNAME'); //發件人姓名
$mail->AddAddress($to,"尊敬的客戶");
$mail->WordWrap = 50; //設置每行字符長度
$mail->IsHTML(C('MAIL_ISHTML')); // 是否HTML格式郵件
$mail->CharSet=C('MAIL_CHARSET'); //設置郵件編碼
$mail->Subject =$title; //郵件主題
$mail->Body = $content; //郵件內容
$mail->AltBody = "這是一個純文本的身體在非營利的HTML電子郵件客戶端"; //郵件正文不支持HTML的備用顯示
$mail->SMTPDebug = 0; // 關閉SMTP調試功能
// 1 = errors and messages
// $mail->ErrorInfo;
// 2 = messages only
if ($mail->send()) {
return true;
} else {
// return $mail->ErrorInfo;
return false;
}
}
~~~
- PHP新特性
- 一些常識
- PHP常見header頭
- Nginx配置文件
- 常用工具類
- PHP實現的一個時間幫助類
- PHP原生生成EXCEL
- PHP地理位置計算
- PHP獲取服務器狀態
- 駝峰轉下劃線
- 百度地圖兩點坐標距離計算
- 判斷是否是url
- 郵件發送類
- 阿拉伯數字轉化為大寫
- 獲取漢字首個拼音
- 根據身份證號獲取星座
- 生成驗證碼類
- 生成唯一ID
- 身份證驗證類
- PHP中文轉拼音
- curl獲取網頁內容
- 快遞查詢api
- 快遞API類
- 上傳圖片類
- 股票類
- 找回密碼類
- 校驗數據規則
- PHP獲取收集相關信息
- 字符串截取助手函數
- 網頁中提取關鍵字
- 檢測瀏覽器語言
- PHP實現微信紅包拆分算法
- 常用函數
- 微信相關
- 網絡知識
- LX1 Laravel / PHP 擴展包視頻教程
- THINKPHP5學習
- 高級查詢
- Vue學習
- Vue全家桶
- Vue-CLI 3.x 自動部署項目至服務器
- Vue2全家桶
- Vue2全家桶之一:vue-cli(vue腳手架)超詳細教程
- Vue2全家桶之二:vue-router(路由)詳細教程,看這個就夠了
- Vue2全家桶之三:vue-resource(不推薦)----axios(推薦)
- 前端相關
- sublime text3 配置less編譯環境
- 服務器搭建相關
- supervisor
- Supervisor 安裝與配置 Linux進程管理
- supervisor 永不掛掉的進程 安裝以及使用
- Supervisor進程管理&開機自啟
- php實現定時任務
- 使用sublime text3 連接sftp/ftp(遠程服務器)
- Redis相關
- linux服務器重啟后導致redis數據丟失
- 搜索引擎SEO
- 百度收錄權威鏈接,指向真正需要收錄的地址rel
- 軟件相關
- sublime
- sublime Text3修改側邊欄的主題
- sublime和vscode比較
- Acrylic DNS Proxy 使用方法
- 技術類網址收藏