i finally committed i guess
Signed-off-by: boris <boris@borishub.co.uk>
This commit is contained in:
79
Databases/generate_users.php
Normal file
79
Databases/generate_users.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
// Connect to the SQLite database
|
||||
$db = new PDO('sqlite:Databases/ecobuddy.sqlite');
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
// List of real first names for usernames
|
||||
$firstNames = [
|
||||
'James', 'John', 'Robert', 'Michael', 'William', 'David', 'Richard', 'Joseph', 'Thomas', 'Charles',
|
||||
'Christopher', 'Daniel', 'Matthew', 'Anthony', 'Mark', 'Donald', 'Steven', 'Paul', 'Andrew', 'Joshua',
|
||||
'Kenneth', 'Kevin', 'Brian', 'George', 'Timothy', 'Ronald', 'Edward', 'Jason', 'Jeffrey', 'Ryan',
|
||||
'Jacob', 'Gary', 'Nicholas', 'Eric', 'Jonathan', 'Stephen', 'Larry', 'Justin', 'Scott', 'Brandon',
|
||||
'Benjamin', 'Samuel', 'Gregory', 'Alexander', 'Frank', 'Patrick', 'Raymond', 'Jack', 'Dennis', 'Jerry',
|
||||
'Tyler', 'Aaron', 'Jose', 'Adam', 'Nathan', 'Henry', 'Douglas', 'Zachary', 'Peter', 'Kyle',
|
||||
'Ethan', 'Walter', 'Noah', 'Jeremy', 'Christian', 'Keith', 'Roger', 'Terry', 'Gerald', 'Harold',
|
||||
'Sean', 'Austin', 'Carl', 'Arthur', 'Lawrence', 'Dylan', 'Jesse', 'Jordan', 'Bryan', 'Billy',
|
||||
'Joe', 'Bruce', 'Gabriel', 'Logan', 'Albert', 'Willie', 'Alan', 'Juan', 'Wayne', 'Elijah',
|
||||
'Randy', 'Roy', 'Vincent', 'Ralph', 'Eugene', 'Russell', 'Bobby', 'Mason', 'Philip', 'Louis'
|
||||
];
|
||||
|
||||
// List of common words for password generation
|
||||
$words = [
|
||||
'Apple', 'Banana', 'Cherry', 'Dragon', 'Eagle', 'Forest', 'Garden', 'Harbor', 'Island', 'Jungle',
|
||||
'Kingdom', 'Lemon', 'Mountain', 'Nature', 'Ocean', 'Planet', 'Queen', 'River', 'Summer', 'Tiger',
|
||||
'Universe', 'Volcano', 'Winter', 'Yellow', 'Zebra', 'Castle', 'Diamond', 'Emerald', 'Flower', 'Galaxy',
|
||||
'Horizon', 'Iceberg', 'Journey', 'Knight', 'Legend', 'Meadow', 'Nebula', 'Oasis', 'Palace', 'Quasar',
|
||||
'Rainbow', 'Sapphire', 'Thunder', 'Unicorn', 'Victory', 'Whisper', 'Xylophone', 'Yacht', 'Zephyr', 'Autumn',
|
||||
'Breeze', 'Cascade', 'Dolphin', 'Eclipse', 'Falcon', 'Glacier', 'Harmony', 'Infinity', 'Jasmine', 'Kaleidoscope',
|
||||
'Lighthouse', 'Mirage', 'Nightfall', 'Orchard', 'Phoenix', 'Quicksilver', 'Radiance', 'Serenity', 'Twilight', 'Umbrella'
|
||||
];
|
||||
|
||||
// Check if we already have users with these names
|
||||
$existingUsers = [];
|
||||
$stmt = $db->query("SELECT username FROM ecoUser");
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$existingUsers[] = $row['username'];
|
||||
}
|
||||
|
||||
// Prepare the SQL statement for inserting users
|
||||
$insertStmt = $db->prepare("INSERT INTO ecoUser (username, password, userType) VALUES (?, ?, ?)");
|
||||
|
||||
// Create a file to store usernames and passwords
|
||||
$file = fopen("user_credentials.txt", "w");
|
||||
fwrite($file, "Username,Password\n");
|
||||
|
||||
// Generate 50 users
|
||||
$usersAdded = 0;
|
||||
$usedNames = [];
|
||||
shuffle($firstNames);
|
||||
|
||||
foreach ($firstNames as $name) {
|
||||
if ($usersAdded >= 50) break;
|
||||
|
||||
// Skip if the name is already in the database
|
||||
if (in_array($name, $existingUsers) || in_array($name, $usedNames)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Generate password in format (Word)(Word)(Word)(Digit)
|
||||
$password = $words[array_rand($words)] . $words[array_rand($words)] . $words[array_rand($words)] . rand(0, 9);
|
||||
|
||||
// Hash the password using SHA-256
|
||||
$hashedPassword = hash('sha256', $password);
|
||||
|
||||
// Insert the user into the database (userType 2 is for standard users)
|
||||
$insertStmt->execute([$name, $hashedPassword, 2]);
|
||||
|
||||
// Write the credentials to the file
|
||||
fwrite($file, "$name,$password\n");
|
||||
|
||||
$usedNames[] = $name;
|
||||
$usersAdded++;
|
||||
|
||||
echo "Added user: $name\n";
|
||||
}
|
||||
|
||||
fclose($file);
|
||||
|
||||
echo "\nSuccessfully added $usersAdded users to the database.\n";
|
||||
echo "Usernames and passwords have been saved to user_credentials.txt\n";
|
Reference in New Issue
Block a user