Last active
August 21, 2019 14:27
-
-
Save davidfergo/0a319e57cebbdf76220952b68cfffc44 to your computer and use it in GitHub Desktop.
Script to generate bcrypt values in command line for use in Java apps
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
#!/usr/bin/env groovy | |
import at.favre.lib.crypto.bcrypt.BCrypt | |
@Grapes( | |
@Grab(group='at.favre.lib', module='bcrypt', version='0.7.0') | |
) | |
public class bcrypt { | |
public static void main(String[] args) { | |
Console console=System.console() | |
Integer iterations = args.length>0 && args[0].isInteger() ? args[0] as int : null | |
String pwd = args.length>1 ? args[1] : "" | |
if (args.length<1) { | |
while(iterations==null) { | |
try { | |
iterations=Integer.parseInt(console.readLine("How many iterations (4-31)? ")) | |
iterations=iterations<4?null:iterations | |
} catch(Exception e) {} | |
} | |
} | |
if (args.length<2) { | |
while(pwd?.length()<1) { | |
pwd=console.readLine("Password? ") | |
} | |
} | |
String generatedSecuredPasswordHash = BCrypt.withDefaults().hashToString(iterations, pwd.toCharArray()) | |
System.out.println("---["+generatedSecuredPasswordHash+"]---"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment