You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Password.java 913 B

2 years ago
1234567891011121314151617181920212223242526272829
  1. package homework.pkg4;
  2. import java.security.MessageDigest;
  3. import java.util.Scanner;
  4. import javax.xml.bind.DatatypeConverter;
  5. public class Password {
  6. public static void main( String[] args ) throws Exception {
  7. Scanner keyboard = new Scanner(System.in);
  8. String un, pw, encrypt_psswrd;
  9. MessageDigest digest = MessageDigest.getInstance("SHA-256");
  10. System.out.print("Please create a username: ");
  11. un = keyboard.nextLine();
  12. System.out.print("Please create a password: ");
  13. pw = keyboard.nextLine();
  14. digest.update( pw.getBytes("UTF-8") );
  15. encrypt_psswrd = DatatypeConverter.printHexBinary( digest.digest() );
  16. //overwrites user's original input so it is not visible to hackers.
  17. pw = "empty";
  18. System.out.println( "Your username is: " + un + ". Your password has been encryped for security purposes: " + encrypt_psswrd );
  19. }
  20. }

No Description

Contributors (1)