Ejemplo n.º 1
0
        public User Create(CreateUserRequest newUser)
        {
            // Generate a salt
            byte[] salt = new byte[128 / 8];
            using (var rng = new RNGCryptoServiceProvider())
            {
                rng.GetBytes(salt);
            }

            // Add salt to the password and hash it all
            string HashedPassword = Convert.ToBase64String(KeyDerivation.Pbkdf2(
                                                               password: newUser.Password,
                                                               salt: salt,
                                                               prf: KeyDerivationPrf.HMACSHA1,
                                                               iterationCount: 10000,
                                                               numBytesRequested: 256 / 8));

            var insertResponse = _context.Users.Add(new User
            {
                FirstName       = newUser.FirstName,
                LastName        = newUser.LastName,
                Email           = newUser.Email,
                Username        = newUser.Username,
                ProfileImageUrl = newUser.ProfileImageUrl,
                CoverImageUrl   = newUser.CoverImageUrl,
                Hashed_password = HashedPassword,
                Salt            = Convert.ToBase64String(salt)
            });

            _context.SaveChanges();

            return(insertResponse.Entity);
        }
Ejemplo n.º 2
0
        public Interaction Create(CreateInteractionRequest create)
        {
            var insertResult = _context.Interactions.Add(new Interaction
            {
                Date   = DateTime.Now,
                Type   = create.InteractionType,
                PostId = create.PostId,
                UserId = create.UserId,
            });

            _context.SaveChanges();
            return(insertResult.Entity);
        }
Ejemplo n.º 3
0
        public Post Create(CreatePostRequest post)
        {
            var insertResult = _context.Posts.Add(new Post
            {
                ImageUrl = post.ImageUrl,
                Message  = post.Message,
                PostedAt = DateTime.Now,
                UserId   = post.UserId,
            });

            _context.SaveChanges();
            return(insertResult.Entity);
        }
        public Post CreatePost(CreatePostRequestModel postModel)
        {
            var insertResult = _context.Posts.Add(new Post
            {
                ImageUrl = postModel.ImageUrl,
                Message  = postModel.Message,
                PostedAt = DateTime.Now,
                UserId   = postModel.UserId,
            });

            _context.SaveChanges();
            return(GetById(insertResult.Entity.Id));
        }
Ejemplo n.º 5
0
        public User Create(CreateUserRequest newUser)
        {
            var insertResponse = _context.Users.Add(new User
            {
                FirstName       = newUser.FirstName,
                LastName        = newUser.LastName,
                Email           = newUser.Email,
                Username        = newUser.Username,
                ProfileImageUrl = newUser.ProfileImageUrl,
                CoverImageUrl   = newUser.CoverImageUrl,
            });

            _context.SaveChanges();

            return(insertResponse.Entity);
        }
Ejemplo n.º 6
0
        public User Create(CreateUserRequest newUser)
        {
            var salt           = _hashHelper.GenerateSalt();
            var insertResponse = _context.Users.Add(new User
            {
                FirstName       = newUser.FirstName,
                LastName        = newUser.LastName,
                Email           = newUser.Email,
                Username        = newUser.Username,
                ProfileImageUrl = newUser.ProfileImageUrl,
                CoverImageUrl   = newUser.CoverImageUrl,
                Salt            = salt,
                HashedPassword  = _hashHelper.GenerateHash(newUser.Password, salt)
            });

            _context.SaveChanges();

            return(insertResponse.Entity);
        }
Ejemplo n.º 7
0
        public User Create(CreateUserRequest newUser)
        {
            byte[] salt           = _hasherNSalter.MakeSalt();
            var    insertResponse = _context.Users.Add(new User
            {
                FirstName       = newUser.FirstName,
                LastName        = newUser.LastName,
                Email           = newUser.Email,
                Username        = newUser.Username,
                ProfileImageUrl = newUser.ProfileImageUrl,
                CoverImageUrl   = newUser.CoverImageUrl,
                PasswordSalt    = salt,
                HashedPassword  = _hasherNSalter.DoHash(newUser.RawPassword, salt)
            });

            _context.SaveChanges();

            return(insertResponse.Entity);
        }
Ejemplo n.º 8
0
 public void Create(CreateInteractionRequestModel newInteraction, int postId)
 {
     _context.Interactions.Add(new Interaction
     {
         Type   = newInteraction.InteractionType,
         PostId = postId,
         UserId = newInteraction.UserId,
         Date   = DateTime.Now,
     });
     _context.SaveChanges();
 }
Ejemplo n.º 9
0
        public User Create(CreateUserRequest newUser)
        {
            IHashService hash           = new HashAlgorithm();
            var          salt           = hash.GetSalt();
            var          insertResponse = _context.Users.Add(new User
            {
                FirstName       = newUser.FirstName,
                LastName        = newUser.LastName,
                Email           = newUser.Email,
                Username        = newUser.Username,
                ProfileImageUrl = newUser.ProfileImageUrl,
                CoverImageUrl   = newUser.CoverImageUrl,
                Salt            = salt,
                HashedPassword  = hash.HashPassword(salt, newUser.Password)
            });

            _context.SaveChanges();

            return(insertResponse.Entity);
        }
Ejemplo n.º 10
0
 public void CreatePost(CreatePostRequestModel postModel)
 {
     _context.Posts.Add(new Post
     {
         ImageUrl = postModel.ImageUrl,
         Message  = postModel.Message,
         PostedAt = DateTime.Now,
         UserId   = postModel.UserId,
     });
     _context.SaveChanges();
 }
 public void Create(CreateInteractionRequestModel newInteraction, Post post, User user)
 {
     _context.Interactions.Add(new Interaction
     {
         Type = newInteraction.InteractionType,
         Post = post,
         User = user,
         Date = DateTime.Now,
     });
     _context.SaveChanges();
 }
Ejemplo n.º 12
0
        public User Create(CreateUserRequest newUser)
        {
            string salt = HashSalt.GetSalt();

            var insertResponse = _context.Users.Add(new User
            {
                FirstName       = newUser.FirstName,
                LastName        = newUser.LastName,
                Email           = newUser.Email,
                Username        = newUser.Username,
                ProfileImageUrl = newUser.ProfileImageUrl,
                CoverImageUrl   = newUser.CoverImageUrl,
                HashedPassword  = HashSalt.HashPassword(newUser.Password, salt),
                Salt            = salt
            });

            _context.SaveChanges();

            return(insertResponse.Entity);
        }
Ejemplo n.º 13
0
 public void CreatePost(CreatePostRequestModel postModel, User postedBy)
 {
     _context.Posts.Add(new Post
     {
         ImageUrl = postModel.ImageUrl,
         ImageAlt = postModel.ImageAlt,
         Message  = postModel.Message,
         PostedAt = DateTime.Now,
         User     = postedBy,
     });
     _context.SaveChanges();
 }
Ejemplo n.º 14
0
        public User Create(CreateUserRequest newUser)
        {
            var          salt     = _hashService.GetSalt();
            const string password = "******";

            var insertResponse = _context.Users.Add(new User
            {
                FirstName       = newUser.FirstName,
                LastName        = newUser.LastName,
                Email           = newUser.Email,
                Username        = newUser.Username,
                ProfileImageUrl = newUser.ProfileImageUrl,
                CoverImageUrl   = newUser.CoverImageUrl,
                HashedPassword  = _hashService.HashPassword(salt, password),
                Salt            = salt
            });

            _context.SaveChanges();

            return(insertResponse.Entity);
        }
Ejemplo n.º 15
0
 public void Create(CreateUserRequestModel newUser)
 {
     _context.Users.Add(new User
     {
         FirstName       = newUser.FirstName,
         LastName        = newUser.LastName,
         Email           = newUser.Email,
         Username        = newUser.Username,
         ProfileImageUrl = newUser.ProfileImageUrl,
         CoverImageUrl   = newUser.CoverImageUrl,
     });
     _context.SaveChanges();
 }
Ejemplo n.º 16
0
        public User Create(CreateUserRequest newUser)
        {
            var password = newUser.Password;

            byte[] salt = new byte[128 / 8];
            using (var rng = System.Security.Cryptography.RandomNumberGenerator.Create())
            {
                rng.GetBytes(salt);
            }
            string convertedSalt = Convert.ToBase64String(salt);


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

            Console.WriteLine(hashed);
            Console.WriteLine(convertedSalt);
            var insertResponse = _context.Users.Add(new User
            {
                FirstName       = newUser.FirstName,
                LastName        = newUser.LastName,
                Email           = newUser.Email,
                Username        = newUser.Username,
                ProfileImageUrl = newUser.ProfileImageUrl,
                CoverImageUrl   = newUser.CoverImageUrl,
                HashedPassword  = hashed,
                Salt            = convertedSalt
            });

            _context.SaveChanges();

            return(insertResponse.Entity);
        }