Skip to content

Commit 6af4eb6

Browse files
committed
Add password hashing utility with Argon2 and Bcrypt support
1 parent 399654c commit 6af4eb6

3 files changed

Lines changed: 68 additions & 1 deletion

File tree

bun.lock

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
"server": "bun src/server/index.ts",
1111
"server:node": "node dist/server/index.js",
1212
"build": "tsc",
13-
"watch": "tsc -w"
13+
"watch": "tsc -w",
14+
"gen-hash": "bun src/utils/gen-hash.ts",
15+
"gen-hash:node": "node dist/utils/gen-hash.js"
1416
},
1517
"author": "ysdragon",
1618
"license": "MIT",
1719
"dependencies": {
1820
"@dank074/discord-video-stream": "5.0.1",
21+
"@types/bcrypt": "^6.0.0",
1922
"@types/bun": "^1.2.23",
23+
"argon2": "^0.44.0",
2024
"axios": "^1.12.2",
2125
"bcrypt": "^6.0.0",
2226
"discord.js-selfbot-v13": "^3.7.0",

src/utils/gen-hash.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as bcrypt from 'bcrypt';
2+
import argon2 from 'argon2';
3+
4+
const password = process.argv[2];
5+
const hashType = process.argv[3] || 'argon2';
6+
7+
if (!password) {
8+
console.error('Usage: bun/node run gen-hash <password> [type]');
9+
console.error('\tExample: bun/node run gen-hash mySecurePassword123 argon2');
10+
console.error('\tExample: bun/node run gen-hash mySecurePassword123 bcrypt');
11+
console.error('\nSupported types: argon2 (default), bcrypt');
12+
process.exit(1);
13+
}
14+
15+
if (hashType !== 'argon2' && hashType !== 'bcrypt') {
16+
console.error(`Error: Invalid hash type "${hashType}"`);
17+
console.error('Supported types: argon2, bcrypt');
18+
process.exit(1);
19+
}
20+
21+
let hash: string;
22+
23+
if (hashType === 'argon2') {
24+
hash = await argon2.hash(password, {
25+
type: argon2.argon2id,
26+
memoryCost: 65536, // 64 MB
27+
timeCost: 3,
28+
parallelism: 4
29+
});
30+
console.log('\n✅ Argon2 hash generated successfully!\n');
31+
} else {
32+
const saltRounds = 10;
33+
hash = bcrypt.hashSync(password, saltRounds);
34+
console.log('\n✅ Bcrypt hash generated successfully!\n');
35+
}
36+
37+
const escapedHash = hash.replace(/\$/g, '\\$');
38+
console.log('Add this to your .env file:');
39+
console.log(`SERVER_PASSWORD = "${escapedHash}"`);
40+
console.log('\nRaw hash:');
41+
console.log(escapedHash);

0 commit comments

Comments
 (0)