예제 #1
0
        /// <summary>
        /// Authenticates the user.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns>AuthenticatedUser.</returns>
        public AuthenticatedUser AuthenticateUser(UsernameAndPassword args)
        {
            var single = _database.Single<User, object>("User_GetOwnerPasswordByUsername", new { args.Username }, _database.AutoPopulate<User>);

            bool isValid = ValidatePassword(args, single);
            return (isValid ? new AuthenticatedUser { Username = single.Username } : null);
        }
        /// <summary>
        /// Binds the model to a value by using the specified controller context and binding context.
        /// </summary>
        /// <param name="controllerContext">The controller context.</param>
        /// <param name="bindingContext">The binding context.</param>
        /// <returns>The bound value.</returns>
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            string username = controllerContext.RequestContext.HttpContext.Request["username"];
            string password = controllerContext.RequestContext.HttpContext.Request["password"];
            var creds = new UsernameAndPassword(username, password);

            return creds;
        }
예제 #3
0
 /// <summary>
 /// Validates the password.
 /// </summary>
 /// <param name="args">The args.</param>
 /// <param name="single">The single.</param>
 /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
 private bool ValidatePassword(UsernameAndPassword args, User single)
 {
     bool isValid = false;
     if (single != null)
     {
         try
         {
             isValid = _crypto.IsMatch(args.Password, single.Password);
         }
         catch
         {
             isValid = false;
         }
     }
     return isValid;
 }
예제 #4
0
 public ActionResult Index(UsernameAndPassword usernameAndPassword)
 {
     var success = Redirect(string.Format("/{0}", usernameAndPassword.Username));
     return Form(usernameAndPassword, success);
 }