Search code examples
androiddatabaseandroid-studioormormlite

How to Create Login query with android orm?


I need to create a login page with Android Studio and my question is how to create login query with Suger ORM? Please answer me just with orm (netter answer me with Suger ORM but is not different in other orms) because I know how to create login query with SQLite database. Thanks everyone and sorry for bad English :)

    Suger.findWithQuery(User.class, "SELECT user_name and password from suger where " + "user_name= ? AND password= ?", name, pass);

This my Code!!! i create Method and my Method return The true; i sayd in clicklistener button if this method return a true Toast to me (Successful) else sayd to me show Failed!! But is my problem its is always for any typing in edit text The Toast is show successful !!!! the field name and pass i get the text from two edit text


Solution

  • Welcome to SO, Ali!

    Since you have not provided enough information about your question I'm going to assume that you are familiar with android enough to create an activity, having two edittext in it and a login button, so on the onClickListener event of the login button you need to query your database for the provided Login info (say email address as user name). following snippet is a simple way to query a table in Sugar Orm

    List<User> users = User.findWithQuery(User.class,"SELECT * FROM USER WHERE email = ?",email);
    

    obviously users may have zero length which means no user exists with this email or one member which is your user, now you need to verify the password, preferably stored using a hash algorithm.

    moreover, I would like to mention Android Room which is a component from Android Arch Components , an orm designed by Android team which is simpler than other ORMs and have great benefits such as being Lifecycle aware.