예제 #1
0
파일: User.cs 프로젝트: dekkerb115/Bam.Net
        public string GetPassword(string answer)
        {
            PasswordQuestion question = PasswordQuestionsByUserId.FirstOrDefault();
            string           result   = string.Empty;

            if (question == null)
            {
                Log.AddEntry("Unable to retrieve password for {0}, password question not set", UserName);
            }

            if (question.Answer.Equals(answer))
            {
                Password password = PasswordsByUserId.FirstOrDefault();
                if (password == null)
                {
                    Log.AddEntry("Unable to retrieve password for {0}, password not set", UserName);
                }

                result = Aes.Decrypt(password.Value);
            }
            else
            {
                Log.AddEntry("Unable to retrieve password for {0}, invalid password ", UserName);
            }
            return(result);
        }
예제 #2
0
파일: User.cs 프로젝트: dekkerb115/Bam.Net
        public bool ChangePasswordQuestionAndAnswer(string password, string newPasswordQuestion, string newPasswordAnswer)
        {
            Password pass   = PasswordsByUserId.FirstOrDefault();
            bool     result = false;

            if (pass == null)
            {
                Log.AddEntry("Unable to change password question and answer, user password was not set");
            }
            else
            {
                string decrypted = Aes.Decrypt(pass.Value);
                if (decrypted.Equals(password))
                {
                    PasswordQuestion question = PasswordQuestionsByUserId.FirstOrDefault();
                    if (question == null)
                    {
                        question = PasswordQuestionsByUserId.AddNew();
                    }

                    question.Value  = newPasswordQuestion;
                    question.Answer = newPasswordAnswer;
                    question.Save();

                    result = true;
                }
            }
            return(result);
        }