示例#1
0
 public function validation()
 {
     // check for empty fields
     $this->validate(new Validator\PresenceOf(['field' => 'email', 'message' => 'U heeft geen email ingevoerd']));
     $this->validate(new Validator\PresenceOf(['field' => 'username', 'message' => 'U heeft geen username ingevoerd']));
     $this->validate(new Validator\PresenceOf(['field' => 'password', 'message' => 'U heeft geen password ingevoerd']));
     $this->validate(new Validator\PresenceOf(['field' => 'voornaam', 'message' => 'U heeft geen voornaam ingevoerd']));
     $this->validate(new Validator\PresenceOf(['field' => 'achternaam', 'message' => 'U heeft geen achternaam ingevoerd']));
     // check if field contains a correct format email
     $this->validate(new Validator\Email(['field' => 'email', 'message' => 'geen correcte emailadres', 'allowEmpty' => true]));
     // check if email is unique in the DB
     $this->validate(new Validator\Uniqueness(['field' => 'email', 'message' => 'dit emailadres is al in gebruik', 'allowEmpty' => true]));
     // check if username is unique in the DB
     $this->validate(new Validator\Uniqueness(['field' => 'username', 'message' => 'deze username is al in gebruik', 'allowEmpty' => true]));
     // checks if phonenumber is of a numerical value
     $this->validate(new Validator\Numericality(['field' => 'telefoonnummer', 'message' => 'dit is geen geldige telefoonnummer', 'allowEmpty' => true]));
     // checks if phonenumber has a StringLength of min 10 and max 10 numbers
     $this->validate(new Validator\StringLength(['field' => 'telefoonnummer', 'max' => '10', 'min' => '10', 'messageMaximum' => 'telefoonnummer mag niet langer zijn dan 10 karakters', 'messageMinimum' => 'telefoonnummer mag niet korter zijn dan 10 karakters', 'allowEmpty' => true]));
     // checks if password has a StringLength of max 30 and min 4
     $this->validate(new Validator\StringLength(['field' => 'password', 'max' => '30', 'min' => '4', 'messageMaximum' => 'password mag niet langer zijn dan 30 karakters', 'messageMinimum' => 'password mag niet korter zijn dan 4 karakters', 'allowEmpty' => true]));
     if ($this->validationHasFailed()) {
         return false;
     }
     $security = new Security();
     // hashes given password to bcrypt hash. This hash has 61 characters
     $this->password = $security->hash($this->password);
 }
示例#2
0
 public function create()
 {
     $email = $this->request->getPost('email');
     $passwd = $this->request->getPost('passwd');
     $user = User::findFirst([['email' => $email]]);
     if ($user) {
         return '邮箱已存在,可以直接登入';
     }
     $security = new Security();
     $user = new User();
     $user->email = $email;
     $user->passwd = $security->hash($passwd);
     if ($user->save()) {
         return $user->attrs();
     } else {
         return '已暂停注册';
     }
 }
    public function validation(){
        $this->validate(new Validator\Email([
            'field'=>'email',
            'message'=>'Your Email Is Invalid !'
        ]));
        $this->validate(new Validator\Uniqueness([
            'field'=>'email',
            'message'=>'Your Email Is In Use !'
        ]));
        $this->validate(new Validator\StringLength([
            'field'=>'password',
            'max'=>'30',
            'min'=>'4',
            'messageMaximum'=>'Your Password Must be Under 30 Characters',
            'messageMinimum'=>'Your Password Must be At Least 4 Characters'
        ]));

        if($this->validationHasFailed()){
            return false;
        }

        $security=new Security();
        $this->password=$security->hash($this->password);
    }
示例#4
0
 public function hash($password, $workFactor = 0)
 {
     return parent::hash($password, $workFactor);
 }
示例#5
0
 /**
  * Performs one-way encryption of a user's password using PHP's bcrypt
  *
  * @param string $rawPassword the password to be encrypted
  * @return bool|string
  */
 public static function encryptPassword($rawPassword)
 {
     $security = new Security();
     return $security->hash($rawPassword);
 }
示例#6
0
 public function setPassword($newPassword)
 {
     $security = new Security();
     $this->pass = $security->hash($newPassword);
 }