-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (43 loc) · 1.12 KB
/
index.js
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
45
46
47
48
49
50
51
const express = require('express')
const app= express()
const mysql=require('mysql2')
const cors =require('cors')
const {encrypt, decrypt} = require('./EncryptionHandler');
app.use(cors());
app.use(express.json());
const db = mysql.createConnection({
user:'root',
host: 'localhost',
password: 'Atul@786',
database: 'passwordmanager',
});
app.post("/addpassword", (req,res)=>{
const {password,title}=req.body;
const hashedPassword= encrypt(password);
db.query("INSERT INTO passwords (password,title,iv) VALUES (?,?,?)",
[hashedPassword.password,title,hashedPassword.iv],
(err, result) => {
if(err){
console.log(err);
} else{
res.send("SUCCESS");
}
}
)
})
app.get('/showpasswords', (req,res) => {
db.query("SELECT * FROM passwords;", (err,result) => {
if(err){
console.log(err);
} else{
res.send(result);
}
})
})
app.post('/decryptpassword', (req,res) => {
res.send(decrypt(req.body))
})
const PORT = 3001
app.listen(PORT , ()=>{
console.log(`Server is running ${PORT}`);
});