小編給大家分享一下php如何實(shí)現(xiàn)修改密碼功能,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
創(chuàng)新互聯(lián)一直在為企業(yè)提供服務(wù),多年的磨煉,使我們?cè)趧?chuàng)意設(shè)計(jì),網(wǎng)絡(luò)營(yíng)銷推廣到技術(shù)研發(fā)擁有了開(kāi)發(fā)經(jīng)驗(yàn)。我們擅長(zhǎng)傾聽(tīng)企業(yè)需求,挖掘用戶對(duì)產(chǎn)品需求服務(wù)價(jià)值,為企業(yè)制作有用的創(chuàng)意設(shè)計(jì)體驗(yàn)。核心團(tuán)隊(duì)擁有超過(guò)十載以上行業(yè)經(jīng)驗(yàn),涵蓋創(chuàng)意,策化,開(kāi)發(fā)等專業(yè)領(lǐng)域,公司涉及領(lǐng)域有基礎(chǔ)互聯(lián)網(wǎng)服務(wù)德陽(yáng)電信服務(wù)器托管、重慶App定制開(kāi)發(fā)、手機(jī)移動(dòng)建站、網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)絡(luò)整合營(yíng)銷。php實(shí)現(xiàn)修改密碼的方法:首先進(jìn)行前端頁(yè)面布局;然后創(chuàng)建“
修改密碼
”;接著通過(guò)js判斷密碼;最后通過(guò)php后臺(tái)處理修改密碼即可。
PHP實(shí)現(xiàn)登錄,注冊(cè),密碼修改
注冊(cè),登錄,修改密碼
1.登錄
2.忘記密碼
3.免費(fèi)注冊(cè)
{sh:$wxuser.nickname}
登錄
忘記密碼
免費(fèi)注冊(cè)
立即登錄
立即登錄
//用戶登錄 public function userLogin() { if(IS_AJAX && !$this->member) { $tel = $this->_post('tel', 'trim'); $password = $this->_post('password', 'trim,md5'); $member = M('Member')->where(array('tel' => $tel))->find(); if ($member && $member['password'] === $password) { //檢測(cè)是否存在微信用戶需要綁定 if ($member['wxuser_id'] == 0 && $this->wxuser) { M('Member')->where(array('id' => $member['id']))->save(array('wxuser_id' => $this->wxuser_id)); } $href = session(LASTREQUEST); session(MEMBER, $member['id']); session(LASTREQUEST, null); $this->ajaxReturn(array('result' => true, 'href' => $href ? $href : U('Member/index'))); } else { if (empty($member)) { $this->ajaxReturn(array('result' => false, 'error' => '手機(jī)號(hào)尚未注冊(cè).')); } else { $this->ajaxReturn(array('result' => false, 'error' => '密碼不正確.')); } } } else { $this->ajaxReturn(array('result' => false, 'error' => '非法請(qǐng)求.')); } } // 用戶退出 public function userLogout() { session(WXUSER, null); session(MEMBER, null); $this->success('退出成功',U('Store/Member/index')); } // 用戶注冊(cè) public function userRegister() { $tel = $this->_post('tel', 'trim'); $password = $this->_post('password', 'trim,md5'); $smscode = $this->_post('smscode', 'trim'); $session_smscode = session($this->smscode); $user_exit = M('Member')->where(array('tel' => $tel))->find(); if (!preg_match("/1[3458]{1}\d{9}$/", $tel) && $user_exit) { $this->ajaxReturn(array('result' => false, 'error' => '手機(jī)號(hào)不合法')); } $memberModel = M('Member'); // 檢測(cè)是否已注冊(cè) $member = $memberModel-> where(array('tel' =>$tel,'status'=>1))->find(); if (!empty($member)) { $this->ajaxReturn(array('result' => false, 'error' => '已是注冊(cè)用戶')); } if (time() > $session_smscode['time'] || $smscode != $session_smscode['code']) { $this->ajaxReturn(array('result' => false, 'error' => '驗(yàn)證碼不正確')); //--調(diào)試,先把驗(yàn)證功能關(guān)閉 } $data = array('tel' => $tel, 'password' => $password, 'wxuser_id' => intval($this->wxuser_id), 'addtime' => time()); $insert_id = $memberModel->add($data); if ($insert_id) { $href = session(LASTREQUEST); session(MEMBER, $insert_id); //*****只是一個(gè)id值 $this->ajaxReturn(array('result' => true, 'href' => $href ? $href : U('Member/index'))); } else { $this->ajaxReturn(array('result' => false, 'error' => '操作失敗', 'msg' => M('Member')->getError())); } } //用戶更改密碼 public function changePwd(){ $tel = $this->_post('tel','trim'); $password = $this ->_post('password','trim'); $smscode = $this ->_post('smscode','trim'); $session_smscode = session($this ->smscode); if (time() > $session_smscode['time'] || $smscode != $session_smscode['code']) { $this->ajaxReturn(array('result' => false, 'error' => '驗(yàn)證碼不正確')); //--調(diào)試成功 } $data = array('password' => md5($password), 'addtime' => time()); $memberModel = M('Member'); // 檢測(cè)是否已注冊(cè) $member = $memberModel-> where(array('tel' =>$tel,'status'=>1))->find(); if (empty($member)) { $this->ajaxReturn(array('result' => false, 'error' => '號(hào)碼尚未注冊(cè)')); } if ($memberModel->where(array('tel'=> $tel))->save($data)) { $href = session(LASTREQUEST); session(MEMBER, $member['id']); $this->ajaxReturn(array('result' => true, 'href' => $href ? $href : U('Member/index'))); } else { $this->ajaxReturn(array('result' => false, 'error' => '操作失敗', 'msg' => M('Member')->getError())); } } // ajax檢測(cè)號(hào)碼是否注冊(cè) public function checkTel() { $tel = $this->_post('tel', 'trim'); if (IS_AJAX && preg_match("/1[3458]{1}\d{9}$/",$tel)) { $memberModel = M('Member'); $member = $memberModel->where(array('tel'=>$tel,'status'=>1))->find(); if (!empty($member)) { $this->ajaxReturn(array('status' => 1, 'info' => '已注冊(cè)')); } else { $this->ajaxReturn(array('status' => 2, 'info' => '未注冊(cè)')); } } else { $this->ajaxReturn(array('status' => 3, 'info' => '錯(cuò)誤的請(qǐng)求')); } } //發(fā)送注冊(cè)驗(yàn)證碼 public function sendSmscode() { session($this->smstime, null); $smstime = session($this->smstime); $tel = $this->_post('tel', 'trim'); if (IS_AJAX && (!$smstime || time() > $smstime) && preg_match("/1[3458]{1}\d{9}$/",$tel)) { $smscode = rand(1000, 9999); //發(fā)送【阿里大魚(yú)】的驗(yàn)證碼 require LIB_PATH . 'ORG/Taobao-sdk-php/TopSdk.php'; $c = new TopClient; $c->appkey = '23307560'; // 原23294081 $c->secretKey = '21ef24dd4c51e20693c5db0983c433e7'; // 原0402169f466d8fed780e7f07edd25177 $req = new AlibabaAliqinFcSmsNumSendRequest; $req->setSmsType("normal"); $req->setSmsFreeSignName("注冊(cè)驗(yàn)證"); $req->setSmsParam('{"code":"'. $smscode .'","product":"【多多助店寶】"}'); $req->setRecNum("{$tel}"); $req->setSmsTemplateCode("SMS_5056863"); $resp = $c->execute($req); if(!$resp->code) { //設(shè)置發(fā)送限制時(shí)間 session($this->smstime, time() + 50); //設(shè)置驗(yàn)證碼5分鐘內(nèi)有效 session($this->smscode, array('code' => $smscode, 'time' => time() + 600)); } else { //發(fā)送失敗寫(xiě)入日志文件 $log = date('Y-m-d H:i:s') . " 發(fā)送失敗 sub_code:{$resp->sub_code} sub_msg:{$resp->sub_msg}" . PHP_EOL; file_put_contents(RUNTIME_PATH . 'Log/smscode.log', $log, FILE_APPEND); } $this->ajaxReturn(array('result' => !$resp->code)); } else { $this->ajaxReturn(array('result' => false, 'error' => '錯(cuò)誤的請(qǐng)求')); } } //發(fā)送修改密碼驗(yàn)證碼 public function sendSmsexcode(){ session($this->smstime, null); $smstime = session($this->smstime); $tel = $this->_post('tel', 'trim'); if (IS_AJAX && (!$smstime || time() > $smstime) && preg_match("/1[3458]{1}\d{9}$/",$tel)) { $smscode = rand(1000, 9999); //發(fā)送【阿里大魚(yú)】的驗(yàn)證碼 require LIB_PATH . 'ORG/Taobao-sdk-php/TopSdk.php'; $c = new TopClient; $c->appkey = '23307560'; // 原23294081 $c->secretKey = '21ef24dd4c51e20693c5db0983c433e7'; // 原0402169f466d8fed780e7f07edd25177 $req = new AlibabaAliqinFcSmsNumSendRequest; $req->setSmsType("normal"); $req->setSmsFreeSignName("變更驗(yàn)證"); //短信簽名固定,不可以換其他字 $req->setSmsParam('{"code":"'. $smscode .'","product":"【多多助店寶】"}'); $req->setRecNum("{$tel}"); $req->setSmsTemplateCode("SMS_5056861"); $resp = $c->execute($req); if(!$resp->code) { //設(shè)置發(fā)送限制時(shí)間 session($this->smstime, time() + 50); //設(shè)置驗(yàn)證碼5分鐘內(nèi)有效 session($this->smscode, array('code' => $smscode, 'time' => time() + 600)); } else { //發(fā)送失敗寫(xiě)入日志文件 $log = date('Y-m-d H:i:s') . " 發(fā)送失敗 sub_code:{$resp->sub_code} sub_msg:{$resp->sub_msg}" . PHP_EOL; file_put_contents(RUNTIME_PATH . 'Log/smscode.log', $log, FILE_APPEND); } $this->ajaxReturn(array('result' => !$resp->code)); } else { $this->ajaxReturn(array('result' => false, 'error' => '錯(cuò)誤的請(qǐng)求')); } }
以上是“php如何實(shí)現(xiàn)修改密碼功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!