Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package br.ufg.inf.es.seg.userEditor;
- import java.io.File;
- import java.io.FileWriter;
- import java.security.MessageDigest;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.Scanner;
- import org.apache.commons.codec.binary.Hex;
- /**
- *
- * @author rafael
- */
- public class UserEditor {
- static ArrayList<String> roles = new ArrayList<String>();
- public static Scanner input = new Scanner(System.in);
- public static void writeTextToFile(String text, File filename) throws Exception {
- FileWriter writer = new FileWriter(filename, true);
- writer.write(text);
- writer.close();
- }
- public static String getHash(byte[] messageBytes) throws Exception {
- MessageDigest md = MessageDigest.getInstance("MD5");
- byte[] msgDigest = md.digest(messageBytes);
- String hash = new String(Hex.encodeHex(msgDigest));
- return hash;
- }
- public static void main(String args[]) throws Exception {
- System.out.println("Nome do novo usuário:");
- String newUserName = input.nextLine();
- System.out.println("Senha do novo usuário:");
- String password = input.nextLine();
- String user;
- user = newUserName + ":" + getHash(password.getBytes()) + ":";
- String role;
- do {
- System.out.println("Papeis do usuário:");
- role = input.nextLine();
- System.out.println("Deseja adicionar outro papel? (Y/N)");
- } while (!"n".equalsIgnoreCase(input.nextLine()));
- System.out.println(user);
- }
- }
Add Comment
Please, Sign In to add comment