gpt4 book ai didi

android - sqlite 表将任何字符串视为正确的用户名和密码

转载 作者:行者123 更新时间:2023-11-29 20:19:19 25 4
gpt4 key购买 nike

** 注册表将任何字符串视为有效**

登录类

there is a register table and there are fields FirstName,LastName and Password i check edittext values to the register table .... but it returns true for any String.....

 package com.example.app;

import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class login extends Activity{

EditText e1,e2;
Button b1;

DBHandler handler=new DBHandler(this);
//SQLiteDatabase db=handler.getWritableDatabase();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);

e1=(EditText)findViewById(R.id.e_l_fnm);
e2=(EditText)findViewById(R.id.e_l_lnm);
b1=(Button)findViewById(R.id.b_login);
b1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

String fname=e1.getText().toString();
String pwd=e2.getText().toString();
if(fname.equals("") || pwd.equals(""))
{
Toast.makeText(getApplicationContext(), "fields are required", Toast.LENGTH_SHORT).show();
}
else
{
handler.login(fname, pwd);
Toast.makeText(getApplicationContext(), "login successfull", Toast.LENGTH_SHORT).show();
// Intent i=new Intent(login.this,home.class);
// startActivity(i);
}
}
});
}

}

登录方法(DBHandler类)

public boolean login(String fname,String pwd)
{
SQLiteDatabase db=this.getWritableDatabase();
Cursor c=db.rawQuery("SELECT * FROM " + TABLE_REGISTER + " WHERE FirstName=? AND Password=?", new String[]{fname,pwd});
if(c!=null)
{
if(c.getCount()<0)
{
return false;
}
}
return true;
}

最佳答案

使用 if-else 验证 handler.login 方法调用结果,如果条件为 true 则开始下一步,否则显示“无效”的警报消息登录”:

if(handler.login(fname, pwd)){
// use login successful
}else{
// login failed
}

关于android - sqlite 表将任何字符串视为正确的用户名和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33462050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com