コード例 #1
0
        public ActionResult Authenticate(User model)
        {
            User user = UserRepository.GetUser(model.Username);

            if (user != null)
            {
                if (model.Password == user.Password)
                {
                    // generate a random code
                    String code = MainController.RandomString(10);
                    user.Code = code;
                    user.Timeout = DateTime.Now.AddSeconds(60);

                    ViewBag.Username = user.Username;

                    // send mail
                    var message = new MailMessage();
                    message.To.Add(new MailAddress(user.Email));
                    message.From = new MailAddress("*****@*****.**");
                    message.Subject = "Authentication code";
                    message.Body = "Input the following code in the next 60 seconds: " + code;
                    message.IsBodyHtml = false;

                    var smtp = new SmtpClient();
                    smtp.Host = "localhost";
                    smtp.Send(message);

                    return View("Authenticate");
                }
                else
                {
                    return View("Login");
                }
            }
            else
            {
                return View("Login");
            }
        }
コード例 #2
0
        public static Dictionary<String, User> GetUsers(String path)
        {
            if (_users == null)
            {
                _users = new Dictionary<String, User>();

                String[] lines = File.ReadAllLines(path);

                foreach (String line in lines)
                {
                    String[] userParams = line.Split(';');

                    User user = new User();
                    user.Username = userParams[0];
                    user.Password = userParams[1];
                    user.Email = userParams[2];

                    _users.Add(user.Username, user);
                }
            }

            return _users;
        }