gpt4 book ai didi

java - 帮助进行密码验证

转载 作者:行者123 更新时间:2023-12-02 00:46:34 24 4
gpt4 key购买 nike

我创建了一个登录应用程序。但是当我输入错误的密码时,该应用程序不会给我任何密码错误的通知,因为我什至没有输入任何代码。我不知道要付出什么才能实现它。我是这里的新手。请帮忙。

这是我的代码:

public void onClick(View v)
{
EditText passwordEditText = (EditText) findViewById(R.id.currentPass);
SharedPreferences prefs = this.getApplicationContext().getSharedPreferences("prefs_file",MODE_PRIVATE);
String password = prefs.getString("password","");
if("".equals(password))
{
Editor edit = prefs.edit();
edit.putString("password",passwordEditText.getText().toString());
edit.commit();
StartMain();
}
else
{
if(passwordEditText.getText().toString().equals(password))
{
StartMain();
}
}

}

最佳答案

您可能希望在内部 if 语句中添加 else 条件:

if(passwordEditText.getText().toString().equals(password)) //checking if they put the right password?
{
StartMain(); //I assume this is starting the application
}
else
{
//Tell them the password was wrong.
}

关于java - 帮助进行密码验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4835451/

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