Ejemplo n.º 1
0
        /// <summary>
        /// Инициализация данных БД
        /// </summary>
        /// <returns></returns>
        public async Task Initialize()
        {

            if (!await _databaseContext.Users.AnyAsync())
            {

                #region Пользователи

                var adminSalt = new Random().GenerateSequence(16);
                var admin = new User()
                {
                    Login = "******",
                    Name = "SD",
                    Email = "*****@*****.**",
                    PasswordHash = _hashProvider.HashString("3228",adminSalt), // fX7nZzbZlODInUuDmW3RYg==
                    PasswordSalt = adminSalt
                };

                _databaseContext.Users.Add(admin);

                #endregion

                
            }

            await _databaseContext.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Регистрация
        /// </summary>
        /// <param name="registrationModel"></param>
        /// <returns></returns>
        public async Task Registration(RegistrationModel registrationModel)
        {
            var  salt = Convert.ToString(Guid.NewGuid());
            User user = new User
            {
                UserGuid     = Guid.NewGuid(),
                Login        = registrationModel.Login,
                Email        = registrationModel.Mail,
                Name         = registrationModel.Name,
                PasswordSalt = salt,
                PasswordHash = _hashProvider.HashString(registrationModel.Password)
            };

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();
        }
Ejemplo n.º 3
0
        public static string HashString(string inputString, IHashProvider hashProvider, bool isCaseSensitive)
        {
            string result = null;

            if (inputString != null)
            {
                if (hashProvider != null)
                {
                    if (!isCaseSensitive)
                    {
                        inputString = inputString.ToUpperInvariant();
                    }
                    return(hashProvider.HashString(inputString));
                }
                result = inputString;
            }
            return(result);
        }