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

111
Views
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
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!