Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C#
if(loginAttempt<4 && !loginStatus.equals("Locked") ){
                        statement = connection.prepareStatement("update user_data_management set attempt=?,status =? where user_code=? ");
                        if (loginStatus.equals("Logged"))
                            throw new UserAlreadyLoggedIn();
                        else
                            statement.setInt(1, loginAttempt);
                        statement.setString(2, "Open");
                        statement.setString(3,userID);
                        statement.executeUpdate();
                        throw new PasswordNotValidException();
                    }else{
                        statement = connection.prepareStatement("update user_data_management set status =? where user_code=? ");
                        statement.setString(1,"Locked");
                        statement.setString(2,userID);
                        statement.executeUpdate();
                        throw new UserLockedException("Your LoginId and Password is blocked");
                    }

                }
            }else
                throw new PasswordNotValidException();


        }catch (SQLException e) {
            e.printStackTrace();
            throw new DataRetrievalFailureException();
Posted

1 solution

Adda new date/time field called "Until" and add a new "Hiatus" value to user_code.

When user tries to log in too many times, set user_code to "Hiatus" and set Until value to DateTime.Now + 24 hours.

Next time they try to log in, if user_code equals "Hiatus" and DateTime.Now < new field Until ... display error to user.

Otherwise, set user_code to "Logged" and continue log-in process.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900