Ejemplo n.º 1
0
        public static bool UpdateLoginRecord(IProcessor processor, string email, string username, int uid)
        {
            bool valid = false;

            try
            {
                // generate new password
                string newPasword = Reusables.GetPassword();

                // update login record
                MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
                byte[] hashedDataBytes = null;
                UTF8Encoding encoder = new UTF8Encoding();

                hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(newPasword));

                using (EFDbContext context = new EFDbContext())
                {
                    var login = (from l in context.logins
                                 where l.UID == uid
                                 select l).FirstOrDefault();

                    if (login != null)
                    {
                        login.Errors = 0;
                        login.Modified_On = DateTime.Now;
                        login.EncryptedPassword = hashedDataBytes;

                        // *** marked out for testing
                        context.SaveChanges();
                    }
                }

                // send welcome email
                processor.ProcessNewPasswordSendEmail(email, username, newPasword);

                valid = true;
            }
            catch (Exception ex)
            {

            }
            return valid;
        }