0
我忙於創建一個投票系統,即一旦他們登錄一個人只能投票。我遇到的問題是,當我嘗試登錄,即使有正確的密碼,我else if
聲明仍然觸發代碼不正確的密碼行,我不知道爲什麼它這樣做。這是工作過,但添加新表到我的數據庫後,它只是停止工作。密碼不正確的SQLite
這裏是我的數據庫代碼:
public class LoginDataBaseAdapter {
static final String DATABASE_NAME = "votersystem.db";
static final int DATABASE_VERSION = 1;
public static final int NAME_COLUMN = 4;
static final String CREATE_ADDRESS_TABLE = "create table "+"ADDRESS"+
"("+"ID integer primary key autoincrement,"+"PROVINCE text," +"MUNICIPALITY text,"+"STREET text,"+"CITY text,"+"FLAT text,"+"TRIBE text,"+"SUBURB text,"+"TOWN text,"+"POST text) ";
static final String CREATE_LOGIN_TABLE = "create table "+"LOGIN"+
"(" +"ID integer primary key autoincrement,"+"UNAME text," +"EMAIL text,"+"IDNUMBER text,"+"UPHONE text,"+"DIS text," +"PASSWORD text,"+"REPASSWORD text,"+ "SECURITYHINT text) ";
static final String CREATE_ADMIN_TABLE = "create table "+"ADMIN"+
"(" +"ID integer primary key autoincrement,"+ "FIRSTNAME text,"+"LASTNAME text,"+"PARTY text,"+ "SYMBOL text) ";
static final String CREATE_REPORT_TABLE = "create table "+"REPORT"+"(" +"ID integer primary key autoincrement,"+ "FULLNAME text,"+"PARTY text"+")";
public SQLiteDatabase db;
private final Context context;
private DataBaseHelper dbHelper;
private Cursor mCursor;
public LoginDataBaseAdapter(Context _context)
{
context = _context;
dbHelper = new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public LoginDataBaseAdapter open() throws SQLException
{
db = dbHelper.getWritableDatabase();
return this;
}
public void close()
{
db.close();
}
public SQLiteDatabase getDatabaseInstance()
{
return db;
}
public void insertEntry(String Prov, String Mun, String str, String cty, String flt, String trb, String sburb, String twn, String pst)
{
ContentValues newValues = new ContentValues();
newValues.put("PROVINCE",Prov);
newValues.put("MUNICIPALITY",Mun);
newValues.put("STREET",str);
newValues.put("CITY",cty);
newValues.put("FLAT",flt);
newValues.put("TRIBE",trb);
newValues.put("SUBURB",sburb);
newValues.put("TOWN",twn);
newValues.put("POST",pst);
db.insert("ADDRESS", null, newValues);
}
public void insertEntry(String User, String email,String idnumber,String Phone,String Dis, String password,String repassword,String securityhint)
{
ContentValues newValues = new ContentValues();
newValues.put("UNAME",User);
newValues.put("EMAIL",email);
newValues.put("IDNUMBER",idnumber);
newValues.put("UPHONE",Phone);
newValues.put("DIS",Dis);
newValues.put("PASSWORD", password);
newValues.put("REPASSWORD",repassword);
newValues.put("SECURITYHINT",securityhint);
db.insert("LOGIN", null, newValues);
}
public int deleteEntry(String User)
{
String where="UNAME=?";
int numberOFEntriesDeleted= db.delete("LOGIN", where, new String[]{User}) ;
return numberOFEntriesDeleted;
}
public String getSinlgeEntry(String User)
{
Cursor cursor=db.query("LOGIN", null, " UNAME=?", new String[]{User}, null, null, null);
if(cursor.getCount()<1) // UserName Not Exist
{
cursor.close();
return "NOT EXIST";
}
cursor.moveToFirst();
String password= cursor.getString(cursor.getColumnIndex("PASSWORD"));
cursor.close();
return password;
}
public String getAllTags(String a) {
Cursor c = db.rawQuery("SELECT * FROM " + "LOGIN" + " where SECURITYHINT = '" +a + "'" , null);
String str = null;
if (c.moveToFirst()) {
do {
str = c.getString(c.getColumnIndex("PASSWORD"));
} while (c.moveToNext());
}
return str;
}
,這裏是我的Java編碼,我有我的if
聲明允許用戶進入下一個頁面,或者給出了一個不正確的密碼錯誤消息:
public class LoginAndRegistrion extends Activity {
LoginDataBaseAdapter loginDataBaseAdapter;
Button login;
Button registerr;
EditText Username,enterpassword;
TextView forgetpass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_registration);
login=(Button)findViewById(R.id.login_btn);
registerr=(Button)findViewById(R.id.register_btn);
Username=(EditText)findViewById(R.id.nam_ent_edt);
enterpassword=(EditText)findViewById(R.id.password_edt);
forgetpass=(TextView)findViewById(R.id.textView2);
loginDataBaseAdapter = new LoginDataBaseAdapter(getApplicationContext());
loginDataBaseAdapter.open();
registerr.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i=new Intent(LoginAndRegistrion.this,Registration.class);
startActivity(i);
}
});
login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String Uusername=Username.getText().toString();
String Password=enterpassword.getText().toString();
String storedPassword=loginDataBaseAdapter.getSinlgeEntry(Uusername);
if(Password.equals(storedPassword))
{
Intent ii=new Intent(LoginAndRegistrion.this,OtpSubmitScreen.class);
startActivity(ii);
}
else
if(Password.equals("")){
Toast.makeText(LoginAndRegistrion.this, "Please Enter Your Password", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(LoginAndRegistrion.this, "Password Incorrect", Toast.LENGTH_LONG).show();
}
}
});
上一次我只是想念一個縮進。但是,這一次我不知道爲什麼它會觸發我的密碼不正確的語句,甚至當我輸入正確的用戶名和密碼。
我錯過了什麼?