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

112
Vistas
Login problem with mongo dB on my dynamic website using a Linux based codio server

Can anyone tell my why my login system isn't working on my server? it just returns user not found even though the users table in my mongo DB contains a valid username and password that I use. here is the code I use to try login.

app.post('/dologin', function (req, res) {
    console.log(JSON.stringify(req.body))
    var uname = req.body.username;
    var pword = req.body.password;

    db.collection('users').findOne({
        "SignIn.username": uname
    }, function (err, result) {
        if (err) throw err;

        if (!result) {
            res.redirect('/SignIn');
            console.log("user not found :(")
            return
        }

        if (result.SignIn.password == pword) {
            req.session.loggedin = true;
            req.session.currentuser = uname;
            res.redirect('pages/UserAccount')
            console.log("a user was recognised, horay!")
        } else {
            res.redirect('/SignIn')
            console.log("user not found :(")
        }
    });
});

this is the form used to take in the username and password it is stored in a file called SignIn.ejs:

<form action="/dologin" method="POST">
    <input class="UsernameBox" type="text" placeholder="username"  name="username"> 
    <input class="PasswordBox" type="password" placeholder="password"  name="password">
    <button class="LogInButton" type="submit">login</button> 
</form>

the MongoDB stores its username and passwords in a table called users

I need to get this going in the next day so any help would be greatly appreciated

about 4 years ago · Santiago Trujillo
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