Advertisement
Guest User

Untitled

a guest
Feb 9th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. public class LoginSystem {
  2. private static LoginSystem instance = null;
  3. private ArrayList<User> userList;
  4. private User loggedUser = null;
  5.  
  6. protected LoginSystem(){
  7. userList = new ArrayList<User>();
  8. }
  9. public static LoginSystem getInstance(){
  10. if(instance == null){
  11. instance = new LoginSystem();
  12. }
  13. return instance;
  14. }
  15.  
  16. public boolean Login(String login, String password){
  17. User temp = null;
  18. for (User user : userList) {
  19. if(user.username.equals(login)){
  20. temp = user;
  21. break;
  22. }
  23. }
  24. if(temp == null)
  25. return false;
  26. if(!LoginSystem.byteArrayToHexString((login + "!" + password).getBytes()).equals(temp.password))
  27. return false;
  28. loggedUser = temp;
  29. return true;
  30. }
  31.  
  32. public static String byteArrayToHexString(byte[] b) {
  33. String result = "";
  34. for (int i=0; i < b.length; i++) {
  35. result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );
  36. }
  37. return result;
  38. }
  39.  
  40. public static boolean Register(String login, String password)
  41. {
  42. instance.userList.add(new User(login, password));
  43. return true;
  44. }
  45. }
  46.  
  47. class User {
  48. String username;
  49. String password;
  50.  
  51. public User(String username, String password){
  52. this.username = username;
  53. this.password = LoginSystem.byteArrayToHexString((username + "!" + password).getBytes());
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement