-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.sterl.hash</groupId> | ||
<artifactId>hash-root</artifactId> | ||
<version>0.1.1-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>hash-cli</artifactId> | ||
<name>hash-cli</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.sterl.hash</groupId> | ||
<artifactId>hash-lib</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-cli</groupId> | ||
<artifactId>commons-cli</artifactId> | ||
<version>1.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>2.4.0</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
<configuration> | ||
<mainClass>org.sterl.hash.HashMain</mainClass> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.sterl.hash; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.CommandLineParser; | ||
import org.apache.commons.cli.DefaultParser; | ||
import org.apache.commons.cli.HelpFormatter; | ||
import org.apache.commons.cli.Options; | ||
|
||
public class HashMain { | ||
|
||
private final static Options options = new Options(); | ||
static { | ||
options.addOption("a", true, "Algrorithmus one of " + Arrays.toString(Algorithm.values())); | ||
//options.addOption("m", "method", false, "HTTP method to use."); | ||
//options.addOption("p", "payload", false, "String payload to send."); | ||
options.addOption("p", "password", true, "Password to hash."); | ||
options.addOption("h", "hash", true, "The hash to check the passwort against. Note you may have to escape $ with an \\."); | ||
} | ||
public static void main(String[] args) { | ||
Algorithm algorithm = Algorithm.BCrypt; | ||
String password = ""; | ||
String hash = null; | ||
|
||
if (args.length > 1) { | ||
final CommandLineParser parser = new DefaultParser(); | ||
try { | ||
final CommandLine cmd = parser.parse(options, args); | ||
|
||
if (cmd.hasOption('a')) { | ||
algorithm = Algorithm.valueOf(cmd.getOptionValue('a')); | ||
} | ||
password = cmd.getOptionValue('p'); | ||
|
||
if (cmd.hasOption('h')) { | ||
hash = cmd.getOptionValue('h'); | ||
} | ||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
System.exit(-1); | ||
} | ||
} else if (args.length == 1) { | ||
password = args[0]; | ||
} else { | ||
HelpFormatter formatter = new HelpFormatter(); | ||
formatter.printHelp("hash-cli", options); | ||
System.exit(-1); | ||
} | ||
if (hash == null) { | ||
System.out.println(new BCryptPbkdf2PasswordHash(algorithm).encode(password)); | ||
} else { | ||
System.out.println(new BCryptPbkdf2PasswordHash(algorithm).matches(password, hash)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters