Guest User

Untitled

a guest
Oct 26th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. // Validate Credentials
  2. app.post('/home', (req, res) => {
  3.  
  4. const username = req.body.inputUsername;
  5. const password = req.body.inputPassword;
  6.  
  7. const sessionID = req.cookies['session-id'];
  8. const cookieToken = req.cookies['csrf-token'];
  9.  
  10. if (username === 'root' && password === 'root') {
  11.  
  12. console.log("Home: Logged with valid credentials");
  13.  
  14. // Generating Session ID and Token
  15. const SESSION_ID = uuidv1();
  16. const CSRF_TOKEN = uuidv4();
  17.  
  18. if (!sessionID && !cookieToken) {
  19. console.log(`Generated Session ID: ${SESSION_ID}, CSRF Token: ${CSRF_TOKEN}`);
  20. // Setting Cookie on Header
  21. res.setHeader('Set-Cookie', [`session-id=${SESSION_ID}`, `time=${Date.now()}`, `csrf-token=${CSRF_TOKEN}`]);
  22. } else {
  23. console.log('POST /home Some Session ID and CSRF Token Found')
  24. }
  25.  
  26.  
  27. res.sendFile('views/form.html', {root: __dirname});
  28. } else {
  29. const error = {status: 401, message: 'Invalid Credentials'};
  30. res.sendFile('views/form-error.html', {root: __dirname});
  31. }
  32.  
  33. });
Add Comment
Please, Sign In to add comment