Example usage for org.apache.shiro.crypto.hash.format ParsableHashFormat parse

List of usage examples for org.apache.shiro.crypto.hash.format ParsableHashFormat parse

Introduction

In this page you can find the example usage for org.apache.shiro.crypto.hash.format ParsableHashFormat parse.

Prototype

Hash parse(String formatted);

Source Link

Document

Parses the specified formatted string and returns the corresponding Hash instance.

Usage

From source file:com.masslink.idea.zigbee.shiro.UserPasswordService.java

License:Apache License

@Override
public boolean passwordsMatch(Object submittedPlaintext, String encrypted) {
    ByteSource plaintextBytes = createByteSource(submittedPlaintext);
    if (encrypted == null || encrypted.length() == 0) {
        return plaintextBytes == null || plaintextBytes.isEmpty();
    } else if (plaintextBytes == null || plaintextBytes.isEmpty()) {
        return false;
    }/*from w ww  .  j a v a2 s .  c  o  m*/
    HashFormat discoveredFormat = this.hashFormatFactory.getInstance(encrypted);
    if (discoveredFormat != null && discoveredFormat instanceof ParsableHashFormat) {
        ParsableHashFormat parsableHashFormat = (ParsableHashFormat) discoveredFormat;
        Hash savedHash = parsableHashFormat.parse(encrypted);
        return passwordsMatch(submittedPlaintext, savedHash);
    }
    HashRequest request = createHashRequest(plaintextBytes);
    Hash computed = this.hashService.computeHash(request);
    String formatted = this.hashFormat.format(computed);
    return encrypted.equals(formatted);
}