This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class ValidatePasswordLengthAttribute : ValidationAttribute | |
{ | |
private const string _defaultErrorMessage = "'{0}' must be at least {1} characters long."; | |
private readonly int _minCharacters = Membership.Provider.MinRequiredPasswordLength; | |
public ValidatePasswordLengthAttribute() | |
: base(_defaultErrorMessage) | |
{ | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[PropertiesMustMatch("NewPassword", "ConfirmPassword", ErrorMessage = "The new password and confirmation password do not match.")] | |
public class ChangePasswordModel | |
{ | |
[Required] | |
[DataType(DataType.Password)] | |
[DisplayName("Current password")] | |
public string OldPassword { get; set; } | |
[Required] | |
[ValidatePasswordLength] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LogOnModel | |
{ | |
[Required] | |
[DisplayName("User name")] | |
public string UserName { get; set; } | |
[Required] | |
[DataType(DataType.Password)] | |
[DisplayName("Password")] | |
public string Password { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[PropertiesMustMatch("Password", "ConfirmPassword", ErrorMessage = "The password and confirmation password do not match.")] | |
public class RegisterModel | |
{ | |
[Required] | |
[DisplayName("User name")] | |
public string UserName { get; set; } | |
[Required] | |
[DataType(DataType.EmailAddress)] | |
[DisplayName("Email address")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IFormsAuthenticationService | |
{ | |
void SignIn(string userName, bool createPersistentCookie); | |
void SignOut(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IMembershipService | |
{ | |
int MinPasswordLength { get; } | |
bool ValidateUser(string userName, string password); | |
MembershipCreateStatus CreateUser(string userName, string password, string email); | |
bool ChangePassword(string userName, string oldPassword, string newPassword); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FormsAuthenticationService : IFormsAuthenticationService | |
{ | |
public void SignIn(string userName, bool createPersistentCookie) | |
{ | |
if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName"); | |
FormsAuthentication.SetAuthCookie(userName, createPersistentCookie); | |
} | |
public void SignOut() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MembershipService : IMembershipService | |
{ | |
private readonly MembershipProvider _provider; | |
public MembershipService() | |
: this(null) | |
{ | |
} | |
public MembershipService(MembershipProvider provider) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AccountController : Controller | |
{ | |
private readonly IFormsAuthenticationService formsService; | |
private readonly IMembershipService membershipService; | |
public AccountController(IFormsAuthenticationService formsService, IMembershipService membershipService) | |
{ | |
this.formsService = formsService; | |
this.membershipService = membershipService; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<add namespace="ExampleProject1.Models.Account" /> | |
<add namespace="ExampleProject1.Models.Account.Validation" /> |