Repository navigation
Expand file tree
/
Copy pathGenerateBothHashes.java
More file actions
57 lines (48 loc) · 2.34 KB
/
Copy pathGenerateBothHashes.java
File metadata and controls
57 lines (48 loc) · 2.34 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
45
46
47
48
49
50
51
52
53
54
55
56
// Generate Password Hashes for Both Users
// Run this to get hashes for admin and test user
import java.security.MessageDigest;
import java.util.Base64;
public class GenerateBothHashes {
public static void main(String[] args) {
System.out.println("========================================");
System.out.println("Password Hash Generator");
System.out.println("========================================\n");
// Admin user password
String adminPassword = "rohit0476";
String adminHash = hashPassword(adminPassword);
System.out.println("ADMIN USER:");
System.out.println(" Email: admin@wall.com");
System.out.println(" Password: " + adminPassword);
System.out.println(" Hash: " + adminHash);
System.out.println();
// Test user password
String testPassword = "test123";
String testHash = hashPassword(testPassword);
System.out.println("TEST USER:");
System.out.println(" Email: testuser@wall.com");
System.out.println(" Password: " + testPassword);
System.out.println(" Hash: " + testHash);
System.out.println();
System.out.println("========================================");
System.out.println("SQL INSERT STATEMENTS:");
System.out.println("========================================\n");
System.out.println("-- Admin User");
System.out.println("INSERT INTO users (name, email, password, role, two_factor_enabled, created_at)");
System.out.println("VALUES ('admin', 'admin@wall.com', '" + adminHash + "', 'admin', FALSE, NOW());");
System.out.println();
System.out.println("-- Test User");
System.out.println("INSERT INTO users (name, email, password, role, two_factor_enabled, created_at)");
System.out.println("VALUES ('Test User', 'testuser@wall.com', '" + testHash + "', 'user', FALSE, NOW());");
System.out.println();
}
private static String hashPassword(String password) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] hash = md.digest(password.getBytes());
return Base64.getEncoder().encodeToString(hash);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}