Example #1
0
        public bool ForgetPassword(User user, bool isEmail)
        {
            // validation
            var u = new User();

            if (isEmail)
            {
                u = _context.Users.SingleOrDefault(x => x.Email == user.Email);
                if (u == null)
                {
                    throw new AppException("Email " + user.Email + " not found");
                }
            }
            else
            {
                u = _context.Users.SingleOrDefault(x => x.Phone == user.Phone);
                if (u == null)
                {
                    throw new AppException("Phone " + user.Phone + " not found");
                }
            }

            byte[] passwordHash, passwordSalt;

            Random rnd      = new Random();
            int    tempPass = rnd.Next(111111, 999999);

            CreatePasswordHash(tempPass.ToString(), out passwordHash, out passwordSalt);

            u.PasswordHash = passwordHash;
            u.PasswordSalt = passwordSalt;

            _context.Users.Update(u);
            _context.SaveChanges();

            return(_vcodeService.SendPassword(u, tempPass, isEmail));
        }