public void validateLoginRequest(String username,String uid,String signature,String timestamp) throws DataAccessException, UnauthorizedException {
  if (!Utilities.isTimestampValid(timestamp)) {
    throw new UnauthorizedException("Invalid timestamp: " + timestamp);
  }
  log.info(String.format("Timestamp [ %s ] is valid",timestamp));
  log.info("Validate signature: " + signature);
  UserInfo user=userAuthenticator.getUserInfo(username);
  if (user == null) {
    throw new UnauthorizedException("Couldn't find user: " + username);
  }
  if (!validateSignature(timestamp,user.getHashedPassword(),signature)) {
    throw new UnauthorizedException("Invalid signature: " + signature);
  }
  log.info("Signature matched!!!");
  DeviceInfo device=regenerateKey(uid,user.getUsername());
  log.info("Device found/registered successfully!!!");
  if (!deviceBelongsToUser(user.getUsername(),device.getUsername())) {
    throw new UnauthorizedException(String.format("User [ %s ] doesn't match the device's owner [ %s ]",user.getUsername(),device.getUsername()));
  }
}

public void validateLoginRequest ( String username , String uid , String signature , String timestamp ) throws DataAccessException , UnauthorizedException { if ( ! Utilities . isTimestampValid ( timestamp ) ) { throw new UnauthorizedException ( "Invalid timestamp: " + timestamp ) ; } log . info ( String . format ( "Timestamp [ %s ] is valid" , timestamp ) ) ; log . info ( "Validate signature: " + signature ) ; UserInfo user = userAuthenticator . getUserInfo ( username ) ; if ( user == null ) { throw new UnauthorizedException ( "Couldn't find user: " + username ) ; } if ( ! validateSignature ( timestamp , user . getHashedPassword ( ) , signature ) ) { throw new UnauthorizedException ( "Invalid signature: " + signature ) ; } log . info ( "Signature matched!!!" ) ; DeviceInfo device = regenerateKey ( uid , user . getUsername ( ) ) ; log . info ( "Device found/registered successfully!!!" ) ; if ( ! deviceBelongsToUser ( user . getUsername ( ) , device . getUsername ( ) ) ) { throw new UnauthorizedException ( String . format ( "User [ %s ] doesn't match the device's owner [ %s ]" , user . getUsername ( ) , device . getUsername ( ) ) ) ; } }
verify if the login request is valid . username and uid are authenticated . the timestamp is checked to see it falls within the valid timestamp window . the signature is computed and matched against the given signature . also its checked to see if the uid belongs to the username . this function is useful in identity mode
