I will try to be clear with my question. I'm doing in my application a screen with login where you have to enter the social security number and password, however I am using a system of positions with permission 1-3, I managed to login using social security number and the password,but lack implement the permission. In the database the User is registered with the numbering 1,2 or 3, which grants access to different screens. So when fill the SSN and password, it must be done consulting the permission field to then give access to the screen in question. I'm in doubt on how to bring the value of the permission, with the ssn and password was possible to bring their values compared to what was written in the EditText, but with permission no has this option. How to bring the value? I hope that is clear.
public class Login extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
final EditText txtUserName = (EditText) findViewById(R.id.txtSsn);
final EditText txtPassword = (EditText) findViewById(R.id.txtPass);
findViewById(R.id.btnLogin).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = txtUserName.getText().toString();
String password = txtPassword.getText().toString();
try {
if (username.length() > 0 && password.length() > 0) {
UserDAO dbUser = new UserDAO(Login.this);
dbUser.open();
if (dbUser.Login(username, password)) {
Toast.makeText(Login.this,
"Success!",
Toast.LENGTH_LONG).show();
startActivity(new Intent(getBaseContext(),
ScreenCalendar.class));
} else {
Toast.makeText(Login.this,
"Error",
Toast.LENGTH_LONG).show();
}
dbUser.close();
}
} catch (Exception e) {
Toast.makeText(Login.this, e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
});
}
}
public class UserDAO {
private static String table_name = "users";
private static Context ctx;
private static String[] columns = { "rn", "ssn", "status", "course", "pass",
"permission" };
private DataBase DBHelper;
private SQLiteDatabase db;
public UserDAO(Context ctx) {
this.ctx = ctx;
DBHelper = new DataBase(ctx);
}
public boolean Login(String username, String password) throws SQLException {
Cursor mCursor = db.rawQuery("SELECT * FROM " + table_name
+ " WHERE ssn=? AND pass=?",
new String[] { username, password });
if (mCursor != null) {
if (mCursor.getCount() > 0) {
return true;
}
}
return false;
}
Aucun commentaire:
Enregistrer un commentaire