Bezpieczeństwo ASP.NET MVC

Aby nauczyć się ASP.NET MVC, zbudujemy internetową aplikację.

Część 8:Dodaj bezpieczeństwo.

Bezpieczeństwo aplikacji MVC

Katalog Modelszawiera klasy reprezentujące modele aplikacji.

Automatycznie utworzony przez Visual Web Developer AccountModels.cs zawierające modele używane do uwierzytelniania aplikacji.

Pliki AccountModels zawiera LogOnModelZmianaHasłaModel oraz RegisterModel

Model Zmiana Hasła

public class ZmianaHasłaModel
{
[Required]
[DataType(DataType.Password)]
[Wyświetl(Nazwa = "Bieżące hasło")]
public string StareHasło { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", 
MinimumLength = 6)]
[DataType(DataType.Password)]
[Wyświetl(Nazwa = "Nowe hasło")]
public string NoweHasło { get; set; }
[DataType(DataType.Password)]
[Wyświetl(Nazwa = "Potwierdź nowe hasło")]
[Porównaj("NoweHasło", ErrorMessage = "Nowe hasło i potwierdzenie hasła 
do not match.")]
public string ConfirmPassword { get; set; }
}

Model logowania

public class LogOnModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}

Model rejestracji

public class RegisterModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email address")]
public string Email { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", 
MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password 
do not match.")]
public string ConfirmPassword { get; set; }
}