ASP.NET MVC - Güvenlik

ASP.NET MVC öğrenmek için, bir İnternet uygulaması inşa edeceğiz。

Bölüm 8:güvenlik ekleyin。

MVC uygulaması güvenliği

Models klasörüuygulama modellerini temsil eden sınıfları içerir。

Visual Web Developer otomatik olarak oluşturur HesapModelleri.cs dosyasını, bu dosya uygulama kimlik doğrulaması için kullanılan modelleri içerir。

HesapModelleri içerir LogOnModelChangePasswordModel ve RegisterModel

Parola Değiştirme Modeli

public class ChangePasswordModel
{
[Required]
[DataType(DataType.Password)]
[Display(Name = "Mevcut parola")]
public string OldPassword { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", 
MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Yeni parola")]
public string NewPassword { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Yeni parola onayı")]
[Compare("YeniParola", ErrorMessage = "Yeni parola ve onay parolası 
uyuşmuyor.")]
public string ConfirmPassword { get; set; }
}

Giriş Modeli

public class LogOnModel
{
[Required]
[Display(Name = "Kullanıcı adı")]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Şifre")]
public string Password { get; set; }
[Display(Name = "Beni hatırla?")]
public bool RememberMe { get; set; }
}

Register Modeli

public class RegisterModel
{
[Required]
[Display(Name = "Kullanıcı adı")]
public string UserName { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
[Display(Name = "E-posta adresi")]
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 = "Şifre")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Şifre onayı")]
[Compare("Password", ErrorMessage = "Şifre ve onayı 
uyuşmuyor.")]
public string ConfirmPassword { get; set; }
}