Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda