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?
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With