public function register() { $user_name = I('post.username'); $user_email = I('post.email'); $user_password = I('post.password'); $user_password_confirm = I('post.password_confirm'); //$data = array('user_name'=>$user_name,'user_email'=>$user_email,'user_password'=>$user_password,'user_password_confirm'=>$user_password_confirm); //条件判断 if (empty($user_name)) { $this->ajaxReturn(array('error' => 1, 'msg' => '用户名不能为空!')); return; } if (empty($user_email)) { $this->ajaxReturn(array('error' => 1, 'msg' => '邮箱不能为空!')); return; } if (empty($user_password)) { $this->ajaxReturn(array('error' => 1, 'msg' => '密码不能为空!')); return; } if (!check_username_format($user_name)) { $this->ajaxReturn(array('error' => 1, 'msg' => '请检查你的用户名格式!')); return; } //用户名格式验证 if (!check_email_format($user_email)) { $this->ajaxReturn(array('error' => 1, 'msg' => '请检查你的邮箱格式!')); return; } //邮箱格式验证 if (strlen($user_password) < 6) { $this->ajaxReturn(array('error' => 1, 'msg' => '密码不能小于6位!')); return; } //密码长度验证 if ($user_password !== $user_password_confirm) { $this->ajaxReturn(array('error' => 1, 'msg' => '两次输入的密码不一致!')); return; } //录入操作 $user_salt = get_random_str(6); //盐值 $encrypt_times = rand(1, 10); //encrypy times 加密次数 for ($i = 0; $i < $encrypt_times; $i++) { $user_password = md5($user_password . $user_salt); } //加密 $user = array('user_name' => $user_name, 'user_email' => $user_email, 'user_password' => $user_password, 'user_salt' => $user_salt, 'user_encrypt_times' => $encrypt_times); $result = $this->user_model->add($user); if ($result !== false) { $this->ajaxReturn(array('error' => 0, 'msg' => '注册成功!')); } else { $this->ajaxReturn(array('error' => 1, 'msg' => '注册失败!')); } }
/** * 检查用户名(字母、数字和下划线,第一个字符不能为数字) */ public function checkusername($pusername = '') { $username = !empty($pusername) ? $pusername : $this->input->post('username', true); if (empty($username)) { $response = array('result' => false, 'tip_type' => 'username', 'msg' => $this->lang->line('username_empty')); exit(json_encode($response)); } else { $legal = check_username_len($username) && check_username_format($username); //$this->load->model('filter_model','filter_m'); //$word = $this->filter_m->scan($username); //if (!$word['res'] && $word['msg'] != $this->lang->line('word_exception')) { // $this->check_input(-6); //} $user = $this->member->get_user(array('username'), array('username' => $username)); if ($legal && empty($user)) { if (!empty($pusername)) { return; } else { $response = array('result' => true, 'tip_type' => 'username', 'msg' => ''); exit(json_encode($response)); } } else { $status = !$legal ? -1 : -2; if (!check_username_len($username)) { $status = -7; } elseif (!check_username_format($username)) { $status = -1; } else { $status = -2; } $this->check_input($status); } } }