Skip to content

Instantly share code, notes, and snippets.

@mcsee
Created October 18, 2025 13:54
Show Gist options
  • Save mcsee/ba50d84d91ab9e26cd0a7d84a5fec633 to your computer and use it in GitHub Desktop.
Save mcsee/ba50d84d91ab9e26cd0a7d84a5fec633 to your computer and use it in GitHub Desktop.

Revisions

  1. mcsee created this gist Oct 18, 2025.
    10 changes: 10 additions & 0 deletions login-secure.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    import bcrypt from 'bcrypt';

    app.post('/login', async (req, res) => {
    const { username, password } = req.body;
    const user = await Users.findOne({ username });
    if (!user) return res.status(401).send('Invalid credentials');
    const valid = await bcrypt.compare(password, user.password);
    if (!valid) return res.status(401).send('Invalid credentials');
    res.send('Login successful');
    });