Created
October 26, 2018 15:20
-
-
Save laniltee/59ce18df5996141d6abcc8de6a661a16 to your computer and use it in GitHub Desktop.
validate credentials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Validate Credentials | |
app.post('/home', (req, res) => { | |
const username = req.body.inputUsername; | |
const password = req.body.inputPassword; | |
if (username === 'root' && password === 'root') { | |
console.log("Home: Logged with valid credentials"); | |
// Generating Session ID and Token | |
const SESSION_ID = uuidv1(); | |
const CSRF_TOKEN = uuidv4(); | |
console.log(`Generated Session ID: ${SESSION_ID}, CSRF Token: ${CSRF_TOKEN}`); | |
// Saving token with session ID | |
SESSION_IDS[SESSION_ID] = CSRF_TOKEN; | |
// Setting Cookie on Header | |
res.setHeader('Set-Cookie', [`session-id=${SESSION_ID}`, `time=${Date.now()}`]); | |
res.sendFile('views/form.html', {root: __dirname}); | |
} else { | |
const error = {status: 401, message: 'Invalid Credentials'}; | |
res.sendFile('views/form-error.html', {root: __dirname}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment