Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented fix for crash on login #19

Merged
merged 1 commit into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
implemented fix for crash on login
  • Loading branch information
gabrielconstantin02 committed May 14, 2021
commit 3d75fb62191a898c1936912b18b0b4da1b974c79
66 changes: 33 additions & 33 deletions app/src/main/java/com/example/banking_app/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class Login extends AppCompatActivity {
boolean ok=false;
boolean check=false;
boolean check;
String name;

@Override
Expand Down Expand Up @@ -80,47 +80,47 @@ public void run () {
"/" + databaseProp.getProperty("databaseName") + "?user=" + databaseProp.getProperty("databaseUsername") + "&password=" + databaseProp.getProperty("databasePassword"));
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from USER where email=\""+email+"\" and "+"password=\""+password+"\"");
rs.next();
if(rs.getString(1) != null)
ok = true;
try {
rs.next();
if (rs.getString(1) != null)
ok = true;
}
catch (Exception ignored){

}
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
Log.d("SQLTag", "Failed to execute");
}
check=true;
}
}
public void onLogin(View view) {///Login button
Thread sqlThread = new Thread(new checkSQL());
sqlThread.start();
//wait until the sql statement is executed
while(!check){
public void onLogin(View view) throws InterruptedException {///Login button
Thread sqlThread = new Thread(new checkSQL());
sqlThread.start();
//wait until the sql statement is executed
sqlThread.join(0);
if (ok) {
EditText nameView = (EditText) findViewById(R.id.email);
name = nameView.getText().toString();
ok = false;
EditText emailViewsaved = (EditText) findViewById(R.id.email);
String emailsaved = emailViewsaved.getText().toString();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("emailUser", emailsaved);
editor.commit();

}
if (ok) {
EditText nameView = (EditText) findViewById(R.id.email);
name = nameView.getText().toString();
check=false;
ok=false;
EditText emailViewsaved= (EditText) findViewById(R.id.email);
String emailsaved = emailViewsaved.getText().toString();
SharedPreferences sharedPreferences= PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString("emailUser",emailsaved);
editor.commit();

Intent intent = new Intent(this, MainActivity.class);
// intent.putExtra(MainActivity.EXTRA_MESSAGE, name);
startActivity(intent);
} else {
TextView errorView = (TextView) findViewById(R.id.error);
errorView.setText("Wrong email or password");
check=false;
ok=false;
}
Intent intent = new Intent(this, MainActivity.class);
finish();
startActivity(intent);
} else {
TextView errorView = (TextView) findViewById(R.id.error);
errorView.setText("Wrong email or password");
ok = false;
}
}
public void onSignup(View view) { ///Signup button
public void onSignup(View view) {///Signup button
Intent intent = new Intent(this, Signup.class);
startActivity(intent);
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down