Search code examples
androidapplozic

Applozic Android Chat App - How to check password for a user


I downloaded the Applozic Chat SDK for android. Currently I found that you can login to a user account with the username and any password. I am wonder how should I implement the code to have it check if the user entered the password correctly?


Solution

  • While doing Applozic Login/Register you need to set the user.setAuthenticationTypeId(User.AuthenticationType.APPLOZIC.getValue()); and set the password .If password is incorrect you will get the exception in onFailure of UserLoginTask there you can check for this string in exception Invalid uername/password

    UserLoginTask.TaskListener listener = new UserLoginTask.TaskListener() {                  
    
     @Override          
      public void onSuccess(RegistrationResponse registrationResponse, Context context) {           
     //After successful registration with Applozic server the callback    will come here 
     }                       
    
    @Override             
    public void onFailure(RegistrationResponse registrationResponse, Exception exception) {  
    //If any failure in registration the callback  will come here 
    //Here Invalid uername/password exception will be thrown if password is wrong check for the string Invalid uername/password in exception
    
    }};                      
    
    User user = new User();          
    user.setUserId(userId); //userId it can be any unique user identifier
    user.setDisplayName(displayName); //displayName is the name of the user which will be shown in chat messages
    user.setEmail(email); //optional   
    user.setImageLink("");//optional,pass your image link
    user.setPassword(password);//Set the password
    user.setAuthenticationTypeId(User.AuthenticationType.APPLOZIC.getValue());//You  need to set the Authentication type 
    new UserLoginTask(user, listener, this).execute((Void) null);
    

    Applozic login sample github code link