Skip to content

Instantly share code, notes, and snippets.

@sonOfRa
Created January 17, 2018 18:47
Show Gist options
  • Save sonOfRa/be32884ba1deea00f2b2453245043343 to your computer and use it in GitHub Desktop.
Save sonOfRa/be32884ba1deea00f2b2453245043343 to your computer and use it in GitHub Desktop.
/*
* Copyright 2018 Red Hat, Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* You may elect to redistribute this code under either of these licenses.
*/
package io.vertx.ext.auth.jdbc;
/**
* A more generic HashStrategy to supersede {@link JDBCHashStrategy}
*
* @author <a href="https://github.com/sonOfRa">Simon Levermann</a>
*/
public interface HashStrategy {
/**
* Hash the given password.
*
* @param password the password to hash
* @return a string representation of the password, containing all necessary information to verify it again
*/
String hash(String password);
/**
* Verify a password against a stored hash String, as returned by {@link #hash(String)}
*
* @param plainPassword the password to verify
* @param storedHash the hash to verify against
* @return true if the password matches, false otherwise
*/
boolean verify(String plainPassword, String storedHash);
/**
* Check whether a given password needs to be rehashed.
* <p>
* Modern password hashing algorithms come with a plethora of configuration options. These should be passed
* to the constructor of an implementation of this interface. The parameters should be stored alongside the hash,
* (the hashing functions generally take care of this) and these can then be compared to the settings stored in the
* HashStrategy.
* <p>
* This method can be used when a user logs in, as in this case the plaintext password is available. If it returns
* true, the program can send it through {@link #hash(String)} again to reset it to the new version (after verifying
* of course!)
*
* @param storedHash the hash to check
* @return true if the parameters in the stored hash don't match the parameters given to the strategy
*/
boolean needsRehash(String storedHash);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment