I am creating a simple login form with SharedPreferences.I have put some basic user validation but it is not working. When I enter the username and password and click login button, nothing gets displayed. It should if it is wrong username and password. Below is the code for same.
val userName = findViewById(R.id.user) as EditText
val password = findViewById(R.id.pass) as EditText
val b1 = findViewById(R.id.btn1) as Button
b1.setOnClickListener {
if (userName.equals("") || password.equals(""))
{
Toast.makeText(this, "Username or Password blank", Toast.LENGTH_LONG).show()
}
else if (userName.equals("John") and password.equals("123"))
{
val editor = getSharedPreferences("name", Context.MODE_PRIVATE).edit()
editor.putString("name", userName.getText().toString())
editor.apply()
val intent = Intent(this, Main2Activity::class.java)
intent.putExtra("name", userName.toString())
startActivity(intent)
}
else
{
Toast.makeText(this, "Username or Password Do not Match", Toast.LENGTH_LONG).show()
}
}