Guest User

Untitled

a guest
Feb 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. package br.ufg.inf.es.seg.userEditor;
  2.  
  3. import java.io.File;
  4. import java.io.FileWriter;
  5. import java.security.MessageDigest;
  6. import java.util.ArrayList;
  7. import java.util.Iterator;
  8. import java.util.Scanner;
  9. import org.apache.commons.codec.binary.Hex;
  10.  
  11. /**
  12.  *
  13.  * @author rafael
  14.  */
  15. public class UserEditor {
  16.  
  17.     static ArrayList<String> roles = new ArrayList<String>();
  18.     public static Scanner input = new Scanner(System.in);
  19.  
  20.     public static void writeTextToFile(String text, File filename) throws Exception {
  21.  
  22.         FileWriter writer = new FileWriter(filename, true);
  23.         writer.write(text);
  24.         writer.close();
  25.  
  26.     }
  27.  
  28.     public static String getHash(byte[] messageBytes) throws Exception {
  29.         MessageDigest md = MessageDigest.getInstance("MD5");
  30.         byte[] msgDigest = md.digest(messageBytes);
  31.  
  32.         String hash = new String(Hex.encodeHex(msgDigest));
  33.         return hash;
  34.  
  35.     }
  36.  
  37.     public static void main(String args[]) throws Exception {
  38.  
  39.         System.out.println("Nome do novo usuário:");
  40.         String newUserName = input.nextLine();
  41.  
  42.         System.out.println("Senha do novo usuário:");
  43.         String password = input.nextLine();
  44.  
  45.         String user;
  46.         user = newUserName + ":" + getHash(password.getBytes()) + ":";
  47.  
  48.         String role;
  49.         do {
  50.             System.out.println("Papeis do usuário:");
  51.             role = input.nextLine();          
  52.             System.out.println("Deseja adicionar outro papel? (Y/N)");            
  53.         } while (!"n".equalsIgnoreCase(input.nextLine()));
  54.  
  55.         System.out.println(user);
  56.  
  57.     }
  58. }
Add Comment
Please, Sign In to add comment