question: boolean validatePassword ( final String username , final String password ) { if ( password . length ( ) > 5 ) { boolean allNumbers = true ; try { Integer . parseInt ( password ) ; } catch ( final NumberFormatException e ) { allNumbers = false ; } if ( allNumbers ) { badPasswordReason = "You have used only numbers in your password. This is not a good security practice.\n" + " Are you sure that you want to use this password?" ; } boolean hasUsername = false ; if ( password . contains ( username ) ) { hasUsername = true ; } if ( ! hasUsername ) { debug ( "Checking if password contains a derivative of the username, trimming from the back..." ) ; final int minUserLength = 3 ; for ( int i = 1 ; i < username . length ( ) ; i ++ ) { final String subuser = username . substring ( 0 , username . length ( ) - i ) ; debug ( "\tchecking for \"" + subuser + "\"..." ) ; if ( subuser . length ( ) <= minUserLength ) { break ; } if ( password . contains ( subuser ) ) { hasUsername = true ; debug ( "Password contains username!" ) ; break ; } } if ( ! hasUsername ) { debug ( "Checking if password contains a derivative of the username, trimming from the front..." ) ; for ( int i = 0 ; i < username . length ( ) ; i ++ ) { final String subuser = username . substring ( i ) ; debug ( "\tchecking for \"" + subuser + "\"..." ) ; if ( subuser . length ( ) <= minUserLength ) { break ; } if ( password . contains ( subuser ) ) { hasUsername = true ; debug ( "Password contains username!" ) ; break ; } } } } if ( hasUsername ) { badPasswordReason = "You have used your username or a derivative of your username in your password. This is a bad security practice.\n" + " Are you sure that you want to use this password?" ; return false ; } } else { final String text = "The password you provided is too short. It must be at least 6 characters long." ; if ( isVisible ( ) ) { JOptionPane . showMessageDialog ( getOwner ( ) , text ) ; } else { LOGGER . warn ( text ) ; } return false ; } return true ; }
target:  Do some sanity checks for the password.