-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthenticate.js
More file actions
44 lines (42 loc) · 1.03 KB
/
Copy pathauthenticate.js
File metadata and controls
44 lines (42 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const Client = require('pg').Client;
const client = new Client({
user: "postgres",
password: "root",
host: "localhost",
port: 5432,
database: "apportal"
});
const err=require('./error')
start();
async function start(){
try {
await client.connect();
} catch(e) {
err.error_code(e);
}
}
// Function - Authenticate user
async function login(req,res) {
try {
console.log(parseInt(req.body.userid),req.body.password)
const results = await client.query("select * from personal_details where user_id=$1 AND password=$2;",[parseInt(req.body.userid),req.body.password]);
if (results.rows.length==0)
res.send("Invalid Username Password");
else
res.send("Login successfull");
}
catch(e) {
err.error_code(e);
res.send("ERROR");
}
// finally {
// client.end(() =>
// console.log("Disconnected"));
// }
return;
}
// client.end( () =>
// console.log("Disconnected"));
module.exports = {
login:login
};