Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LoginSystem {
- private static LoginSystem instance = null;
- private ArrayList<User> userList;
- private User loggedUser = null;
- protected LoginSystem(){
- userList = new ArrayList<User>();
- }
- public static LoginSystem getInstance(){
- if(instance == null){
- instance = new LoginSystem();
- }
- return instance;
- }
- public boolean Login(String login, String password){
- User temp = null;
- for (User user : userList) {
- if(user.username.equals(login)){
- temp = user;
- break;
- }
- }
- if(temp == null)
- return false;
- if(!LoginSystem.byteArrayToHexString((login + "!" + password).getBytes()).equals(temp.password))
- return false;
- loggedUser = temp;
- return true;
- }
- public static String byteArrayToHexString(byte[] b) {
- String result = "";
- for (int i=0; i < b.length; i++) {
- result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );
- }
- return result;
- }
- public static boolean Register(String login, String password)
- {
- instance.userList.add(new User(login, password));
- return true;
- }
- }
- class User {
- String username;
- String password;
- public User(String username, String password){
- this.username = username;
- this.password = LoginSystem.byteArrayToHexString((username + "!" + password).getBytes());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement