Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oliviagallucci/ac2838b7643d5f6f09b8f51759fbe835 to your computer and use it in GitHub Desktop.
Save oliviagallucci/ac2838b7643d5f6f09b8f51759fbe835 to your computer and use it in GitHub Desktop.
/**
* Call the database in here and get the response of log in or not
* @param acc - Account object from the user where the password is
* checked according to the database
* @return - status of credential checking
*/
@Override
public boolean checkCredentials(Account acc) {
// send a command to get the user credentials from the database
//THE COMMAND
String query = String.format("select Password from user WHERE UserName='%s'",acc.getUsername());
// print the query
System.out.println(query);
try {
Statement st = this.connect.createStatement();
ResultSet rs = st.executeQuery(query);
while (rs.next()){
System.out.println("queryResult");
// parse the returned result to get the pure password.
this.queryResult = rs.getString(1);
System.out.println(this.queryResult);
}
} catch (SQLException e) {
e.printStackTrace();
return false;
}
//if username not found - returns null OR empty string.
//no account with that username - return false
if (queryResult != null || !queryResult.equals("") ){
System.out.println("pass empty check");
// check the returned password and the acc.getpassword, if same return true, if not false
if(this.queryResult.equals(acc.getPassword())){
System.out.println("pass password check");
return true;
}
}
System.out.println("last false");
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment