Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda