Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.security.MessageDigest;
- import java.util.ArrayList;
- import java.util.Random;
- public class ExperimentMain
- {
- static ArrayList<Account> accountsList = new ArrayList<Account>();
- public static void main(String[] args)
- {
- try
- {
- createAccount("trentv4", "password");
- checkAccount("trentv4", "password");
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- public static void checkAccount(String user, String password)
- {
- for(int i = 0; i < accountsList.size(); i++)
- {
- if(accountsList.get(i).username.equals(user))
- {
- Account act = accountsList.get(i);
- if(act.hash.equals(sha1(act.salt+password)))
- {
- System.out.println("Test");
- }
- }
- }
- }
- public static void createAccount(String user, String password)
- {
- Account account;
- String salt = "";
- Random random = new Random();
- for(int i = 0; i < 10; i++)
- {
- salt += random.nextInt(10);
- }
- account = new Account(user, sha1(salt+password), salt);
- accountsList.add(account);
- }
- static String sha1(String input)
- {
- try
- {
- MessageDigest mDigest = MessageDigest.getInstance("SHA1");
- byte[] result = mDigest.digest(input.getBytes());
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < result.length; i++)
- {
- sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));
- }
- return sb.toString();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- return "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement