mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-09-25 02:39:06 +00:00
Create admin user on first startup
This commit is contained in:
parent
422b1268ca
commit
27d92001c3
1 changed files with 17 additions and 0 deletions
|
@ -9,6 +9,7 @@ using LBPUnion.ProjectLighthouse.Helpers;
|
|||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Logging.Loggers;
|
||||
using LBPUnion.ProjectLighthouse.Match.Rooms;
|
||||
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
|
||||
using LBPUnion.ProjectLighthouse.Startup;
|
||||
using LBPUnion.ProjectLighthouse.StorableLists;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
|
@ -91,6 +92,22 @@ public static class StartupTasks
|
|||
RoomHelper.StartCleanupThread();
|
||||
}
|
||||
|
||||
// Create admin user if no users exist
|
||||
if (serverType == ServerType.Website && database.Users.CountAsync().Result == 0)
|
||||
{
|
||||
const string passwordClear = "lighthouse";
|
||||
string password = CryptoHelper.BCryptHash(CryptoHelper.Sha256Hash(passwordClear));
|
||||
|
||||
User admin = database.CreateUser("admin", password).Result;
|
||||
admin.IsAdmin = true;
|
||||
admin.PasswordResetRequired = true;
|
||||
|
||||
database.SaveChanges();
|
||||
|
||||
Logger.Success("No users were found, so an admin user was created. " +
|
||||
$"The username is 'admin' and the password is '{passwordClear}'.", LogArea.Startup);
|
||||
}
|
||||
|
||||
stopwatch.Stop();
|
||||
Logger.Success($"Ready! Startup took {stopwatch.ElapsedMilliseconds}ms. Passing off control to ASP.NET...", LogArea.Startup);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue