ASP.NET MVC 安全

asp.net mvc - 安全

为了学习 asp.net mvc,我们将构建一个 internet 应用程序。

第 8 部分:添加安全。

mvc 应用程序安全

models 文件夹包含表示应用程序模型的类。

visual web developer 自动创建 accountmodels.cs 文件,该文件包含用于应用程序认证的模型。

accountmodels 包含 logonmodel、changepasswordmodel 和 registermodel:

change password 模型

public class changepasswordmodel
{

[required]
[datatype(datatype.password)]
[display(name = "current password")]
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 = "new password")]
public string newpassword { get; set; }

[datatype(datatype.password)]
[display(name = "confirm new password")]
[compare("newpassword", errormessage = "the new password and confirmation password do not match.")]
public string confirmpassword { get; set; }

}

logon 模型

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; }

}

register 模型

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; }

}

相关文章