Exemple #1
0
        public ListDTO <ChangePasswordDTO> ChangePassword(ChangePassword password)
        {
            ListDTO <ChangePasswordDTO> listPasswordChange = new ListDTO <ChangePasswordDTO>();

            listPasswordChange.Items = new List <ChangePasswordDTO>();

            var user = _context.User.Where(u => u.Id == password.UserId).FirstOrDefault();

            if (password.NewPassword != password.ConfirmPassword)
            {
                listPasswordChange.Items = null;
                return(listPasswordChange);
            }
            if (user != null)
            {
                string passwordHash = Hash.Create(password.Password, user.PasswordSalt);
                password.Password = passwordHash;
            }
            if (user.Password == password.Password)
            {
                Salt   salt         = new Salt();
                var    passwordSalt = salt.ReturnSalt();
                string passwordHash = Hash.Create(password.NewPassword, passwordSalt.ToString());
                user.PasswordSalt = passwordSalt.ToString();
                user.Password     = passwordHash;
                _context.SaveChanges();
                password.Password = user.Password;
                var items = _mapper.Map <ChangePasswordDTO>(password);
                listPasswordChange.Items.Add(items);
            }

            return(listPasswordChange);
        }
Exemple #2
0
        public RegisterUser AddUser(RegisterUser registerUser)
        {
            Random rnd            = new Random();
            int    referralRandom = rnd.Next(1000000, 9999999);

            registerUser.ReferralId = "CRYPTOAPP" + registerUser.Id.ToString() + registerUser.Username + referralRandom.ToString();
            Salt   salt         = new Salt();
            var    passwordSalt = salt.ReturnSalt();
            string passwordHash = Hash.Create(registerUser.Password, passwordSalt.ToString());

            registerUser.PasswordSalt = passwordSalt.ToString();
            registerUser.PasswordHash = passwordHash;
            registerUser.Password     = "******";
            registerUser.PhoneNumber  = " ";
            User user = new User();

            user.Password     = registerUser.PasswordHash;
            user.Username     = registerUser.Username;
            user.ReferralId   = registerUser.ReferralId;
            user.PasswordSalt = passwordSalt.ToString();
            user.Confirmed    = false;
            user.Role         = registerUser.Role;
            //_context.RegisterUser.Add(registerUser);
            _context.User.Add(user);
            _context.SaveChanges();

            EmailModel model = new EmailModel();

            model.EmailTo = "*****@*****.**";
            model.Subject = "test subject";
            model.Message = Body + "http://localhost:4200/validateAccount/" + user.Id + " " + user.Username + user.Token;
            model.UserId  = user.Id;
            emailService.SendEmail(model);
            return(registerUser);
        }
Exemple #3
0
        public bool SetPassword(PasswordToSet password)
        {
            var user = _context.User.Where(u => u.Token == password.Token).FirstOrDefault();

            if (user != null)
            {
                Salt   salt         = new Salt();
                var    passwordSalt = salt.ReturnSalt();
                string passwordHash = Hash.Create(password.Password, passwordSalt.ToString());
                user.PasswordSalt = passwordSalt.ToString();
                user.Password     = passwordHash;
                _context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }