Пример #1
0
        public bool UpdatePassword(int id, string oldPassword, string newPassword)
        {
            var user = operationalDataContext.Users.Find(id);

            if (user.ToUsersDto().IsAuthentic(oldPassword))
            {
                // User-entered password

                var pbkdf2 = new System.Security.Cryptography.Rfc2898DeriveBytes(newPassword, user.Salt);
                pbkdf2.IterationCount = 1000;
                byte[] hash = pbkdf2.GetBytes(32); // Hashed and salted password
                user.EncPassword = hash;
                operationalDataContext.Users.Attach(user);
                operationalDataContext.Entry(user).State = EntityState.Modified;
                operationalDataContext.SaveChanges();
                return(true);
            }
            else
            {
                throw new Exception("Password doesn't match");
            }
        }
Пример #2
0
        public bool ValidateToken(string tokenId)
        {
            var token = _dBContext.UserTokens.ToList().FirstOrDefault(t => t.AuthToken == tokenId && t.ExpiresOn > DateTime.Now);

            if (token != null && !(DateTime.Now > token.ExpiresOn))
            {
                if (token.ExpiresOn != null)
                {
                    token.ExpiresOn = token.ExpiresOn.Value.AddSeconds(
                        Convert.ToDouble(ConfigurationManager.AppSettings["AuthTokenExpiry"]));
                }
                _dBContext.UserTokens.Attach(token);
                _dBContext.Entry(token).State = EntityState.Modified;
                _dBContext.SaveChanges();


                return(true);
            }
            return(false);
        }
Пример #3
0
 public bool UpdateQuestion(FAQDTO faq)
 {
     _dBContext.FAQs.Attach(faq.ToFaq());
     _dBContext.Entry(faq).State = EntityState.Modified;
     return(_dBContext.SaveChanges() > 0);
 }