src/main/java/hr/chembase/web/utils/CryptoUtils.java
public static boolean validateLoginCredentials(final Connection connection, final String username, final String password)
	{
		boolean validationStatus = false;
		PreparedStatement statement = null;
		ResultSet resultSet = null;
		try
		{
			statement = connection.prepareStatement(SQLStatements.GET_LOGIN_CREDENTIALS_SQL);
			statement.setString(1, username);
			resultSet = statement.executeQuery();
			
			if (resultSet.next())
			{
				final String dbSalt = resultSet.getString(1);
				final String dbPasswordHash = resultSet.getString(2);				
				final String passwordHashString = generatePasswordHash(password, dbSalt);

				if (passwordHashString != null && passwordHashString.equals(dbPasswordHash))
				{
					validationStatus = true;
					try
					{
						if (resultSet != null) resultSet.close();
						if (statement != null) statement.close();
					}
					catch (Exception ex) {}
					
					statement = connection.prepareStatement(SQLStatements.POST_LOGIN_RESET_SQL);
					statement.setString(1, username);
					statement.execute();
				}
			}
		}
		catch (Exception ex)
		{
			validationStatus = false;
			throw new RuntimeException(ex);
		}
		finally
		{
			try
			{
				if (resultSet != null) resultSet.close();
				if (statement != null) statement.close();
			}
			catch (Exception ex) {}
		}
		return validationStatus;
	}
/* If validateLoginCredentials return true,
	 * login credentials are correct and a new
	 * sessionID is created for that user
	 */
If validateLoginCredentials return true,
login credentials are correct and a new
sessionID is created for that user
If validateLoginCredentials return true login credentials are correct and a new sessionID is created for that user
public static boolean validateLoginCredentials(final Connection connection, final String username, final String password)
	{
		boolean validationStatus = false;
		PreparedStatement statement = null;
		ResultSet resultSet = null;
		try
		{
			statement = connection.prepareStatement(SQLStatements.GET_LOGIN_CREDENTIALS_SQL);
			statement.setString(1, username);
			resultSet = statement.executeQuery();
			if (resultSet.next())
			{
				final String dbSalt = resultSet.getString(1);
				final String dbPasswordHash = resultSet.getString(2);				
				final String passwordHashString = generatePasswordHash(password, dbSalt);
				if (passwordHashString != null && passwordHashString.equals(dbPasswordHash))
				{
					validationStatus = true;
					try
					{
						if (resultSet != null) resultSet.close();
						if (statement != null) statement.close();
					}
					catch (Exception ex) {}
					statement = connection.prepareStatement(SQLStatements.POST_LOGIN_RESET_SQL);
					statement.setString(1, username);
					statement.execute();
				}
			}
		}
		catch (Exception ex)
		{
			validationStatus = false;
			throw new RuntimeException(ex);
		}
		finally
		{
			try
			{
				if (resultSet != null) resultSet.close();
				if (statement != null) statement.close();
			}
			catch (Exception ex) {}
		}
		return validationStatus;
	}
public static boolean validateLoginCredentials ( final Connection connection , final String username , final String password ) { boolean validationStatus = false ; PreparedStatement statement = null ; ResultSet resultSet = null ; try { statement = connection . prepareStatement ( SQLStatements . GET_LOGIN_CREDENTIALS_SQL ) ; statement . setString ( 1 , username ) ; resultSet = statement . executeQuery ( ) ; if ( resultSet . next ( ) ) { final String dbSalt = resultSet . getString ( 1 ) ; final String dbPasswordHash = resultSet . getString ( 2 ) ; final String passwordHashString = generatePasswordHash ( password , dbSalt ) ; if ( passwordHashString != null && passwordHashString . equals ( dbPasswordHash ) ) { validationStatus = true ; try { if ( resultSet != null ) resultSet . close ( ) ; if ( statement != null ) statement . close ( ) ; } catch ( Exception ex ) { } statement = connection . prepareStatement ( SQLStatements . POST_LOGIN_RESET_SQL ) ; statement . setString ( 1 , username ) ; statement . execute ( ) ; } } } catch ( Exception ex ) { validationStatus = false ; throw new RuntimeException ( ex ) ; } finally { try { if ( resultSet != null ) resultSet . close ( ) ; if ( statement != null ) statement . close ( ) ; } catch ( Exception ex ) { } } return validationStatus ; }
If validateLoginCredentials return true,
 login credentials are correct and a new
 sessionID is created for that user
If validateLoginCredentials return true login credentials are correct and a new sessionID is created for that user