示例#1
0
文件: Database.cs 项目: TwE7k/Pegasus
        public AccountInfo CreateAccount(string username, string password, string ip, Privilege privileges)
        {
            string bcryptPassword = BCryptProvider.HashPassword(password);

            (int rowsEffected, long lastInsertedId) = ExecutePreparedStatement(PreparedStatementId.AccountInsert, username, bcryptPassword, ip, (ushort)privileges);

            var account = new AccountInfo();

            account.Read((uint)lastInsertedId, username, bcryptPassword, privileges);
            return(account);
        }
示例#2
0
        public void AccountCreateCommandHandler(ICommandContext context, string username, string password)
        {
            string encryptedPassword = BCryptProvider.HashPassword(password);

            if (DatabaseManager.Instance.AuthDatabase.CreateAccount(username.ToLower(), encryptedPassword))
            {
                context.SendMessage($"Successfully created Account {username}.");
            }
            else
            {
                context.SendError($"Failed to create account {username}!");
            }
        }
示例#3
0
        public static Account CreateAccount(string username, string password, IPAddress ip, Privilege privileges)
        {
            using (var context = new DatabaseContext())
            {
                context.Account.Add(new Account
                {
                    Username   = username,
                    Password   = BCryptProvider.HashPassword(password),
                    CreateIp   = ip.ToString(),
                    Privileges = (short)privileges
                });

                context.SaveChanges();
                return(context.Account.SingleOrDefault(a => a.Username == username));
            }
        }
示例#4
0
        private static string GetPasswordHash(string password)
        {
            var workFactor = Common.ConfigManager.Config.Server.Accounts.PasswordHashWorkFactor;

            if (workFactor < 4)
            {
                log.Warn("PasswordHashWorkFactor in config less than minimum value of 4, using 4 and continuing.");
                workFactor = 4;
            }
            else if (workFactor > 31)
            {
                log.Warn("PasswordHashWorkFactor in config greater than minimum value of 31, using 31 and continuing.");
                workFactor = 31;
            }

            return(BCryptProvider.HashPassword(password, workFactor));
        }