Login System in NodeJS Excel

0 votes

So, I am creating a basic system which runs a login system in nodejs and express using an Excel file as a base. The excel CSV file will have a list of username and passwords and I am reading it using fast-csv. But when it is authenticating with the listing, it is matching only the first record. Not the other records in the excel. Any clue why? Code is as below:

index.js file

var express = require('express');
var path = require('path');
var app = express();
var bodyParser = require('body-parser');
var csv = require('fast-csv')
var fs = require('fs')

app.listen(80, function(){
    console.log("Server is running")
})

app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.urlencoded({extended : true}));

app.post("/", function (req,res) {
    fs.createReadStream(path.resolve(__dirname, 'master_data.csv'))
    .pipe(csv.parse({ headers: true}))
    .on('error', error => console.error(error))
    .on('data', row => {
        if(req.body.username == row.username && req.body.password === row.password && row.loggedIn == 'FALSE'){
            res.send("Login Successful. <br> Your link is available below:" + row.link)
        }else{
            res.send("Login Failed")
        }
    })
    // Log file created below
    var userSchema = {
        Username: req.body.username,
        loginDateTime: new Date().toString(),
        ipAddress: req.ip,
    };
    fs.appendFile('logfile.txt', JSON.stringify(userSchema) + ",", function(err, file){
        if(err) throw (err);
    })
});

index.html file

<html>
    <head>
        <title>School Login Page</title>
        <link rel="stylesheet" type="text/css" href="./css/mainCSS.css">
    </head>
    <body>
        <h2>School Login Page</h2><br>
        <p>Please enter all details exactly as per details provided to you.</p>
        <form action="/" method="POST">
            <label for="username">Username</label>
            <input type="text" id="username" name="username" value="" required><br><br>
            <label for="password">Password</label>
            <input type="password" id="password" name="password" required><br><br>
            <input type="submit" value="submit" id="submitButton">
        </form>
    </body>
</html>

I also want to create an alert for a failed login but I know that you cannot create alerts server side in nodejs. How can I do this is in the front-end? Thanks

Apr 1 in Database by Edureka
• 9,320 points
35 views

1 answer to this question.

0 votes

This sample contains five javascript files.
request-router.js: This is the request dispatcher javascript file, which is used to handle user requests and call the method of the relevant node module based on the request url path.

home.js: This is a node module js that is used to display welcome messages on the home page when users go to the default url.

login.js: This is a custom node module that handles login-related issues including displaying the login screen and verifying the user's credentials.

register.js: This custom node module contains functions for displaying the registration page and storing user information.

http util.js is a util custom node module that parses request url query strings, creates navigation bars, and generates web pages using template functions.

user-register-and-login-diagram

answered Apr 4 by Edureka
• 8,820 points

Related Questions In Database

0 votes
2 answers
0 votes
1 answer

Can't connect to mysql server in workbench. Kindly please support. username: root & Password: 1234 (i gave)

Hey, @Arivukani, You can see once thing, the solution ...READ MORE

answered Mar 30, 2020 in Database by Gitika
• 65,850 points
682 views
0 votes
1 answer

Change default 'delimiters' in excel

Select a non-empty cell. Do Data -> Text ...READ MORE

answered Feb 21 in Database by Edureka
• 8,820 points
30 views
0 votes
1 answer

Convert a number to a letter in C# for use in Microsoft Excel [duplicate]

If you are familiar with using formulas ...READ MORE

answered Feb 23 in Database by Edureka
• 8,820 points
37 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
918 views
0 votes
1 answer
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,440 points
607 views
0 votes
1 answer

Group by Sum in Excel

It is very easy and you can ...READ MORE

answered Feb 21 in Database by Edureka
• 8,820 points
18 views
0 votes
1 answer

Merging Two excel files as two sheets in one workbook in java

Basically for this, you need to create ...READ MORE

answered Feb 21 in Database by Edureka
• 8,820 points
23 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP