Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate the credentials entered by users with the one in SQLite database

I'm now working on Sample login application in which user can login with their username and password by pressing login button. If the user is new then he/she can also register by choosing username and password. And this registration part of application worked.


My actual question is: How do I compare the user entered credentials with the one that stored in database.

I used SELECT query to select the username and pwd as this

public void ValidateLogin(String un, String pwd)
     {
        SELECT_FROM = "SELECT u_name, u_pwd FROM" + table_name + "WHERE u_name == " + un + "AND u_pwd ==" + pwd;
        db.execSQL(SELECT_FROM);
     }

where username(un) and password(pwd) comes from another java file login.java.


Now please tell me how would I make a successful transition to viewprofile page after successful login?

like image 873
JAaVA Avatar asked Nov 13 '22 12:11

JAaVA


1 Answers

You can use `cursor` with `rawquery` to validate username and password in one boolean type of method

    public boolean ValidateLogin(String un, String pwd)
      {
        boolean chklogin=false;      
        c = db.rawQuery("SELECT u_name, u_pwd FROM " + table_name + " WHERE u_name = '"+ un + "' AND u_pwd ='"+ pwd + "'", null);

         if(c==null)
        {
            //set boolean var to false
               chklogin=false; 
           //message no such records 
         }

        else
         {
           //set boolean var to true 
               chklogin=true;
               c.moveToFirst(); 
         }

         return chklogin; //boolean var
}
like image 109
JAaVA Avatar answered Nov 16 '22 03:11

JAaVA