summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authorLibravatar Ukaykhingmarma28 <ukaykhingmarma28@gmail.com>2025-02-03 13:31:12 +0600
committerLibravatar Ukaykhingmarma28 <ukaykhingmarma28@gmail.com>2025-02-03 13:31:12 +0600
commit4755541b711d3b19af00780e26be0c91223842cc (patch)
tree3edc377821f6c6b03808d2a7877a7756b561d1ef /index.js
parentb23c9aa681c820a569587ccdaaf018c6b9c19f1c (diff)
downloadinventory-4755541b711d3b19af00780e26be0c91223842cc.tar.gz
inventory-4755541b711d3b19af00780e26be0c91223842cc.zip
hash change
Diffstat (limited to 'index.js')
-rw-r--r--index.js8
1 files changed, 4 insertions, 4 deletions
diff --git a/index.js b/index.js
index 017c4c8..d9ba827 100644
--- a/index.js
+++ b/index.js
@@ -49,8 +49,8 @@ async function connectDB() {
connectDB();
-function generateSerialNumber() {
- return `Jadupc${crypto.randomInt(100000, 999999)}`;
+function generateSerialNumber(mac) {
+ return `JPC${crypto.createHash('sha3-224').update(mac).digest('hex').toUpperCase().substring(0, 6)}`;
}
app.post('/upload', async (req, res) => {
@@ -67,10 +67,10 @@ app.post('/upload', async (req, res) => {
const existingDevice = await collection.findOne({ mac });
if (existingDevice) {
- return res.status(400).send('Device with the same MAC address is already registered');
+ return res.status(400).send(`Device with the same MAC address is already registered, ${existingDevice.serialNumber}`);
}
- const serialNumber = generateSerialNumber();
+ const serialNumber = generateSerialNumber(mac);
const newItem = {
serialNumber,