Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- * Created by Martynas on 2017-04-24.
- */
- public class Main {
- private static MessageDigest md;
- public static void main(String[] args) {
- System.out.println("Create login:");
- Scanner scan = new Scanner(System.in);
- String login = scan.next();
- System.out.println("Create password");
- String password = scan.next();
- boolean loggedIn = false;
- while(!loggedIn) {
- System.out.println();
- System.out.println("Write your login:");
- String tempLogin = scan.next();
- if (tempLogin.equals(login)) {
- System.out.println();
- System.out.println("Write your password:");
- String tempPassword = scan.next();
- if(cryptWithMD5(password).equals(cryptWithMD5(tempPassword))){
- System.out.println(cryptWithMD5(password));
- System.out.println("Login successful");
- loggedIn = true;
- } else System.out.println("Wrong password");
- } else System.out.println("wrong login");
- }
- }
- public static String cryptWithMD5(String pass){
- try {
- md = MessageDigest.getInstance("MD5");
- byte[] passBytes = pass.getBytes();
- md.reset();
- byte[] digested = md.digest(passBytes);
- StringBuffer sb = new StringBuffer();
- for(int i=0;i<digested.length;i++){
- sb.append(Integer.toHexString(0xff & digested[i]));
- }
- return sb.toString();
- } catch (NoSuchAlgorithmException ex) {
- Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement