Piwik\Plugins\UsersManager\UsersManager::checkPassword PHP Method

checkPassword() public static method

public static checkPassword ( $password )
    public static function checkPassword($password)
    {
        /**
         * Triggered before core password validator check password.
         *
         * This event exists for enable option to create custom password validation rules.
         * It can be used to validate password (length, used chars etc) and to notify about checking password.
         *
         * **Example**
         *
         *     Piwik::addAction('UsersManager.checkPassword', function ($password) {
         *         if (strlen($password) < 10) {
         *             throw new Exception('Password is too short.');
         *         }
         *     });
         *
         * @param string $password Checking password in plain text.
         */
        Piwik::postEvent('UsersManager.checkPassword', array($password));
        if (!self::isValidPasswordString($password)) {
            throw new Exception(Piwik::translate('UsersManager_ExceptionInvalidPassword', array(self::PASSWORD_MIN_LENGTH)));
        }
    }

Usage Example

Esempio n. 1
0
File: API.php Progetto: bnkems/piwik
 /**
  * Create a user upon call from frontend
  * This API method will be called from Controller of this module
  * 
  * @param String    $userLogin
  * @param String    $userPassword
  * @param String    $userEmail                         
  * @return Boolean
  */
 public function createUser($userLogin, $userPassword, $userEmail)
 {
     if ($userLogin and $userPassword) {
         $userManager = UserManagerAPI::getInstance();
         if (!$this->userManagerModel->userEmailExists($userEmail) and !$this->userManagerModel->userExists($userLogin)) {
             $password = Common::unsanitizeInputValue($userPassword);
             UserManager::checkPassword($password);
             $passwordTransformed = UserManager::getPasswordHash($password);
             $token_auth = $userManager->getTokenAuth($userEmail, $passwordTransformed);
             try {
                 $this->userManagerModel->addUser($userEmail, $passwordTransformed, $userEmail, $userLogin, $token_auth, Date::now()->getDatetime());
                 return true;
             } catch (Exception $e) {
                 //throw new Exception($e->getMessage());
                 $this->__errors[] = 'Error in creating the user in database.';
             }
         } else {
             $this->__errors[] = 'User email already exists or the login name already exists';
         }
     }
     return false;
 }
All Usage Examples Of Piwik\Plugins\UsersManager\UsersManager::checkPassword