Airship\Cabin\Bridge\Blueprint\UserAccounts::isPasswordWeak PHP Method

isPasswordWeak() public method

Is this password too weak?
public isPasswordWeak ( array $post ) : boolean
$post array
return boolean
    public function isPasswordWeak(array $post) : bool
    {
        $state = State::instance();
        if (!isset($this->zxcvbn)) {
            $this->zxcvbn = new Zxcvbn();
        }
        $pw = $post['passphrase'];
        $userdata = \Airship\keySlice($post, ['username', 'display_name', 'realname', 'email']);
        $strength = $this->zxcvbn->passwordStrength($pw, \array_values($userdata));
        $min = $state->universal['minimum_password_score'] ?? self::DEFAULT_MIN_SCORE;
        if ($min < 1 || $min > 4) {
            $min = self::DEFAULT_MIN_SCORE > 4 || self::DEFAULT_MIN_SCORE < 1 ? 4 : self::DEFAULT_MIN_SCORE;
        }
        return $strength['score'] < $min;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Process a user account registration request
  *
  * @param array $post
  */
 protected function processBoard(array $post = [])
 {
     if (empty($post['username']) || empty($post['passphrase'])) {
         $this->lens('board', ['post_response' => ['message' => \__('Please fill out the form entirely'), 'status' => 'error']]);
     }
     if ($this->acct->isUsernameTaken($post['username'])) {
         $this->lens('board', ['post_response' => ['message' => \__('Username is not available'), 'status' => 'error']]);
     }
     if ($this->acct->isPasswordWeak($post)) {
         $this->lens('board', ['post_response' => ['message' => \__('Supplied password is too weak.'), 'status' => 'error']]);
     }
     $userID = $this->acct->createUser($post);
     $_SESSION['userid'] = (int) $userID;
     \Airship\redirect($this->airship_cabin_prefix);
 }