コード例 #1
0
  /**
   * Check the password
   *
   * @param strUserGuid the user guid
   * @param strPassword the password
   * @param plugin the plugin
   * @return true if the password is the same as stored in the database, false otherwise
   */
  public boolean checkPassword(String strUserGuid, String strPassword, Plugin plugin) {
    String strEncryptedPassword = strPassword;

    if (_userParamService.isPasswordEncrypted(plugin)) {
      String strAlgorithm = _userParamService.getEncryptionAlgorithm(plugin);
      strEncryptedPassword = CryptoService.encrypt(strPassword, strAlgorithm);
    }

    return DatabaseUserHome.checkPassword(strUserGuid, strEncryptedPassword, plugin);
  }
コード例 #2
0
  /**
   * Do create a new database user
   *
   * @param user the user
   * @param strPassword the password
   * @param plugin the plugin
   * @return the new database user with a new ID
   */
  public DatabaseUser doCreateUser(DatabaseUser user, String strPassword, Plugin plugin) {
    String strEncryptedPassword = strPassword;

    if (_userParamService.isPasswordEncrypted(plugin)) {
      String strAlgorithm = _userParamService.getEncryptionAlgorithm(plugin);
      strEncryptedPassword = CryptoService.encrypt(strPassword, strAlgorithm);
    }

    user.setPasswordMaxValidDate(SecurityUtils.getPasswordMaxValidDate(_userParamService, plugin));
    user.setAccountMaxValidDate(SecurityUtils.getAccountMaxValidDate(_userParamService, plugin));

    return DatabaseUserHome.create(user, strEncryptedPassword, plugin);
  }
コード例 #3
0
  /**
   * Do modify the password
   *
   * @param user the DatabaseUser
   * @param strPassword the new password not encrypted
   * @param plugin the plugin
   */
  public void doModifyPassword(DatabaseUser user, String strPassword, Plugin plugin) {
    // Updates password
    if (StringUtils.isNotBlank(strPassword)) {
      // Encrypts password or not
      String strEncryptedPassword = strPassword;

      if (_userParamService.isPasswordEncrypted(plugin)) {
        String strAlgorithm = _userParamService.getEncryptionAlgorithm(plugin);
        strEncryptedPassword = CryptoService.encrypt(strPassword, strAlgorithm);
      }

      DatabaseUser userStored = DatabaseUserHome.findByPrimaryKey(user.getUserId(), plugin);

      if (userStored != null) {
        userStored.setPasswordMaxValidDate(
            SecurityUtils.getPasswordMaxValidDate(_userParamService, plugin));
        DatabaseUserHome.updatePassword(userStored, strEncryptedPassword, plugin);
      }
    }
  }