コード例 #1
0
        public async Task <user_response_add> AddUser(user u)
        {
            auth_service _authService = new auth_service(_context);
            auth_hash    pass         = new auth_hash();

            pass       = _authService.Encrypt(u.password);
            u.password = pass.hash;
            u.salt     = pass.salt;
            user_response_add response = new user_response_add();

            response.response = new List <string>();
            if (Validation(u, ref response))
            {
                if (u.id == 0)
                {
                    _context.users.Add(u);
                }
                else
                {
                    _context.users.Update(u);
                }

                await _context.SaveChangesAsync();

                response.success = true;
                response.id      = u.id;
            }

            return(response);
        }
コード例 #2
0
        public auth_hash Encrypt(string password)
        {
            auth_hash response = new auth_hash();


            byte[] salted = new byte[128 / 8];
            using (var rng = RandomNumberGenerator.Create())
            {
                rng.GetBytes(salted);
            }
            response.salt = Convert.ToBase64String(salted);
            response.hash = Convert.ToBase64String(KeyDerivation.Pbkdf2(
                                                       password: password,
                                                       salt: salted,
                                                       prf: KeyDerivationPrf.HMACSHA1,
                                                       iterationCount: 10000,
                                                       numBytesRequested: 256 / 8));

            return(response);
        }