aboutsummaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-07-25 13:00:43 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-07-25 13:00:43 +0530
commit57ac476e3303993ea523c43b7de638d4f1ce3e85 (patch)
tree8078dd2da528fd59c64b29df038efb6f9c04fcfd /backend
parent34297348929e64cc2948f6b675d00674f8e3c347 (diff)
downloadadmin-panel-57ac476e3303993ea523c43b7de638d4f1ce3e85.tar.gz
admin-panel-57ac476e3303993ea523c43b7de638d4f1ce3e85.tar.bz2
admin-panel-57ac476e3303993ea523c43b7de638d4f1ce3e85.zip
fixed bugs
Diffstat (limited to 'backend')
-rw-r--r--backend/hash.js9
-rw-r--r--backend/index.js11
2 files changed, 18 insertions, 2 deletions
diff --git a/backend/hash.js b/backend/hash.js
new file mode 100644
index 0000000..e6d3ba5
--- /dev/null
+++ b/backend/hash.js
@@ -0,0 +1,9 @@
+const bcrypt = require('bcryptjs');
+
+const password = 'password123';
+const saltRounds = 10;
+
+bcrypt.hash(password, saltRounds, function(err, hash) {
+ if (err) throw err;
+ console.log('Hashed password:', hash);
+});
diff --git a/backend/index.js b/backend/index.js
index 9dae733..090296e 100644
--- a/backend/index.js
+++ b/backend/index.js
@@ -7,6 +7,8 @@ const jwt = require('jsonwebtoken');
const app = express();
const PORT = 5000;
+const SECRET_KEY = 'your_jwt_secret'; // Replace with your actual secret key
+
// Middleware
app.use(bodyParser.json());
app.use(cors());
@@ -16,25 +18,30 @@ const users = [
{
id: 1,
username: 'admin',
- password: '$2a$10$QWJkLkFgD1kz6X.0Q1jDg.2aH3eRJ/Qnl72sDgB5DlQvPvFjsKFDi', // hashed password for 'password123'
+ password: '$2a$10$0chEQ/BjpmW2W9J1aA/BNOwF0aeFSBg4IAXnPjjLzSnQmXagdIzra', // hashed password for 'password123'
},
];
// Login route
app.post('/login', async (req, res) => {
const { username, password } = req.body;
+ console.log('Login attempt:', username, password);
const user = users.find((user) => user.username === username);
if (!user) {
+ console.log('User not found');
return res.status(401).json({ message: 'Invalid credentials' });
}
const isPasswordValid = await bcrypt.compare(password, user.password);
+ console.log('Password valid:', isPasswordValid);
if (!isPasswordValid) {
+ console.log('Invalid password');
return res.status(401).json({ message: 'Invalid credentials' });
}
- const token = jwt.sign({ id: user.id }, 'your_jwt_secret', { expiresIn: '1h' });
+ const token = jwt.sign({ id: user.id }, SECRET_KEY, { expiresIn: '1h' });
+ console.log('Token generated:', token);
res.json({ token });
});