Exemple #1
0
        public void UpdateUser(User user)
        {
            var             userdata       = DatabaseObject.UserObject.FirstOrDefault(tg => tg.Id == user.Id);
            EncryptedObject hashedPassword = EncryptedPassword(user.Password);
            UserObject      userObject     = SetUserObject(user, userdata);

            using (TagItDBContext dbContext = new TagItDBContext())
            {
                userObject.HashedPassword = hashedPassword.HasedPassword;
                userObject.PasswordSalt   = hashedPassword.Salt;
                dbContext.UserObject.Update(userObject);
                dbContext.SaveChanges();
            }
        }
Exemple #2
0
        public bool UpdatePassword(Password password)
        {
            var user       = CurrentUser;
            var userObject = DatabaseObject.UserObject.FirstOrDefault(p => p.UserName == user.UserName);

            if (userObject != null && AuthenticatePassword(userObject, password.OldPassword))
            {
                EncryptedObject hashedPassword = EncryptedPassword(password.NewPassword);
                using (TagItDBContext dbContext = new TagItDBContext())
                {
                    userObject.HashedPassword = hashedPassword.HasedPassword;
                    userObject.PasswordSalt   = hashedPassword.Salt;
                    dbContext.UserObject.Add(userObject);
                    dbContext.SaveChanges();
                    return(true);
                }
            }
            return(false);
        }
Exemple #3
0
        public bool CreateUser(User user)
        {
            var userAccount = DatabaseObject.UserObject.FirstOrDefault(p => p.UserName == user.Username);

            if (userAccount != null)
            {
                return(false);
            }
            EncryptedObject hashedPassword = EncryptedPassword(user.Password);
            UserObject      userObject     = SetUserObject(user, null);

            using (TagItDBContext dbContext = new TagItDBContext())
            {
                userObject.HashedPassword = hashedPassword.HasedPassword;
                userObject.PasswordSalt   = hashedPassword.Salt;
                dbContext.UserObject.Add(userObject);
                dbContext.SaveChanges();
            }
            return(true);
        }