Ejemplo n.º 1
0
        internal int AddUserAccount(IncomingNewUserAccount user)
        {
            var account = Context.UserAccounts.Add(new UserAccounts
            {
                Email         = user.Email,
                Password      = user.Password,
                FirstName     = user.FirstName,
                LastName      = user.LastName,
                ProjectRights = user.ProjectRights ? 1 : 0,
                CreationDate  = DateTime.Now
            });

            // generate a 128-bit salt using a secure PRNG
            byte[] salt = new byte[128 / 8];
            using (var rng = RandomNumberGenerator.Create())
            {
                rng.GetBytes(salt);
            }
            Console.WriteLine($"Salt: {Convert.ToBase64String(salt)}");

            // derive a 256-bit subkey (use HMACSHA1 with 10,000 iterations)
            string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
                                                       password: user.Password,
                                                       salt: salt,
                                                       prf: KeyDerivationPrf.HMACSHA1,
                                                       iterationCount: 10000,
                                                       numBytesRequested: 256 / 8));

            account.Entity.Salt     = Convert.ToBase64String(salt);
            account.Entity.Password = hashed;
            Context.SaveChanges();
            return(account.Entity.Id);
        }
Ejemplo n.º 2
0
        public string AddNewUserAccount([FromBody] IncomingNewUserAccount user)
        {
            var accountId = string.Empty;

            using (var context = new UsersContext(Context, Configuration))
            {
                var cAccountId = context.AddUserAccount(user);
                accountId = cAccountId.ToString();
            }
            return(accountId);
        }