Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
How to track failed login attempts during 10 sec

So I'm doing a simple login form with a submit button. So idea is to track the failed attempts when a user tries to log in. If the user failed 5 attempts then submit button will be disabled for 30sec. So far it's pretty simple, but I'm trying to implement that button will be disabled only if those 5 attempts were during the 10sec. So I'm stacked here... Hope for your help folks!

This is what I got so far

const [login, setLogin] = useState<string>('')
const [error, setError] = useState<string>('')
const [attempts, setAttempts] = useState<number>(0)

useEffect(()=>{
    if(attempts===5){
        setTimeout(()=>{
            setAttempts(0)
        },1000)
    }
},[attempts])   

const onChangeHandler = (e: ChangeEvent<HTMLInputElement>) => {
    setLogin(e.target.value)
}

const useHandler = () => {
    setAttempts(prevState => prevState + 1)
    if (login === 'valid') {
        axios.get('https://api.github.com/users/anon').then(res => console.log(res.data))
        setError('')
        setAttempts(0)
    } else if (login !== 'valid') {
        if (attempts >= 0 && attempts < 5) {
            setError('unsuccessful login attempt')
        }
    }
}

and my return here is my return

 <div className="App">
        <div className={'loginBlock'}>
            <div>
                <input name={'login'} value={login} type="text"
                   onChange={onChangeHandler}/>
                <button disabled={attempts === 5} onClick={useHandler}>submit</button>
            </div>
            <div style={{color: 'red'}}>{error}</div>
        </div>
    </div>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!