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.
|
-
- package homework.pkg4;
-
- import java.security.MessageDigest;
- import java.util.Scanner;
- import javax.xml.bind.DatatypeConverter;
-
- public class Password {
- public static void main( String[] args ) throws Exception {
- Scanner keyboard = new Scanner(System.in);
- String un, pw, encrypt_psswrd;
-
- MessageDigest digest = MessageDigest.getInstance("SHA-256");
-
- System.out.print("Please create a username: ");
- un = keyboard.nextLine();
-
- System.out.print("Please create a password: ");
- pw = keyboard.nextLine();
-
- digest.update( pw.getBytes("UTF-8") );
- encrypt_psswrd = DatatypeConverter.printHexBinary( digest.digest() );
-
- //overwrites user's original input so it is not visible to hackers.
- pw = "empty";
-
- System.out.println( "Your username is: " + un + ". Your password has been encryped for security purposes: " + encrypt_psswrd );
- }
- }
|