public String authenticate(String username, byte[] password) { // throws // RemoteException // { UserInterface user = DbObjectServiceModel.GetServerSideInstance().FindUser(username); if (user == null) { return null; } else { try { if (user.Fetch()) { byte[] hashedPassword = user.GetPassword(); MessageDigest.getInstance("SHA-512"); if (MessageDigest.isEqual(password, hashedPassword)) { // authentication successful. // generate a unique string to return it to the client. return java.util.UUID.randomUUID().toString(); } else { // authentication failure. return null; } } } catch (AlreadyDeletedException e) { // the user had already been killed. e.printStackTrace(); return null; } catch (NoSuchAlgorithmException e) { // Should never reach this block, but throw it here anyway. e.printStackTrace(); return null; } } return ""; }
public boolean registerMe( String token, UserInterface user, ClientReceptionInterface cri) { // throws RemoteException { if (alive_users.containsKey(token) && alive_users.get(token).equals(user)) { keepMeAlive(token); return true; } else { alive_users.put(token, user); alive_clients.put(token, new Date()); alive_clients_to_push.put(token, cri); return EngineImpl.GetInstance().register(token, user.GetLastActive()); } }
public boolean unregisterMe(String token, UserInterface user) { // throws // RemoteException // { if (alive_users.containsKey(token) && alive_users.get(token).equals(user)) { if (EngineImpl.GetInstance().unregister(token)) { alive_users.remove(token); alive_clients.remove(token); alive_clients_to_push.remove(token); return user.SetLastActive(new Date()); } else { return false; } } return false; }