Exemplo n.º 1
0
        public void SendRecoveryLetter(UserRecovery recovery, string path)
        {
            var    fromAddress  = new MailAddress("*****@*****.**", "Kampus.com");
            var    toAddress    = new MailAddress(recovery.User.Email, "");
            string fromPassword = "******";
            string subject      = "Відновлення пароля";
            string body         = "Відновіть пароль перейшовши за цим посиланням: " + path + recovery.HashString;

            var smtp = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
            };

            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = body
            })
            {
                smtp.Send(message);
            }
        }
Exemplo n.º 2
0
        public void RecoverPassword(string username, string email, string path)
        {
            User user = GetTable().First(u => u.Username == username);

            if (user.Email == email)
            {
                UserRecovery recovery = new UserRecovery();
                recovery.User       = user;
                recovery.UserId     = user.Id;
                recovery.HashString = (DateTime.Now.Ticks.ToString() + username + email + path).GetEncodedHash();

                SendRecoveryLetter(recovery, path);

                ctx.Recoveries.Add(recovery);

                ctx.SaveChanges();
            }
        }