pwd.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace WY\app\controller\derpay;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class pwd extends CheckAdmin
  8. {
  9. public function index()
  10. {
  11. $data = array('title' => '修改管理员密码');
  12. $this->put('admpwd.php', $data);
  13. }
  14. public function save()
  15. {
  16. $oldpwd = $this->req->post('oldpwd');
  17. $newpwd = $this->req->post('newpwd');
  18. $cirpwd = $this->req->post('cirpwd');
  19. if ($oldpwd == '' || $newpwd == '' || $cirpwd == '') {
  20. echo json_encode(array('status' => 0, 'msg' => '选项填写不完整'));
  21. exit;
  22. }
  23. if (strlen($newpwd) < 6 || strlen($newpwd) > 20) {
  24. echo json_encode(array('status' => 0, 'msg' => '新密码长度为6-20位之间'));
  25. exit;
  26. }
  27. if ($newpwd !== $cirpwd) {
  28. echo json_encode(array('status' => 0, 'msg' => '两次输入的新密码不匹配'));
  29. exit;
  30. }
  31. $cons = array('fields' => 'adminname=?', 'values' => array($this->session->get('login_adminname')));
  32. $data = $this->model()->select('adminpass')->from('admin')->where($cons)->fetchRow();
  33. if ($data && $data['adminpass'] != sha1($oldpwd)) {
  34. echo json_encode(array('status' => 0, 'msg' => '原密码错误'));
  35. exit;
  36. }
  37. $data = array('adminpass' => sha1($newpwd));
  38. if ($this->model()->from('admin')->where($cons)->updateSet($data)->update()) {
  39. echo json_encode(array('status' => 1, 'msg' => '设置保存成功', 'url' => $this->dir . 'pwd'));
  40. exit;
  41. }
  42. echo json_encode(array('status' => 0, 'msg' => '设置保存失败'));
  43. exit;
  44. }
  45. }