我想知道在MVC 5和ASP.NET Identity Framework附带的UserManager中默认实现的Password Hasher是否足够安全?如果是这样,如果你可以向我解释它是如何工作的?
IPasswordHasher界面如下所示:
public interface IPasswordHasher
{
string HashPassword(string password);
PasswordVerificationResult VerifyHashedPassword(string hashedPassword,
string providedPassword);
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,它不需要盐,但在这个帖子中提到:" Asp.net身份密码哈希 ",它确实在幕后加盐.所以我想知道它是如何做到的?这盐来自何处?
我担心的是盐是静态的,使它非常不安全.
我使用asp.net身份创建新用户但收到错误:
无法将值NULL插入列'Id',表'Mydb.dbo.AspNetUsers'; 列不允许空值.INSERT失败.\ r \n语句已终止
但是在这里我没有像AspNetUsers这样的表,而是我拥有自己的用户表.
代码: Web.config:2个连接字符串
<add name="myEntities" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=;initial catalog=mydb;user id=sa;password=sdfsdfsdf;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="MyConnString" connectionString="data source=;initial catalog=Mydb;user id=sa;password=sdfsdfsdf;" providerName="System.Data.SqlClient" />
Run Code Online (Sandbox Code Playgroud)
IdentityModel.cs:
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
this.SecurityStamp = Guid.NewGuid().ToString();
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
public string Id { get; set; }
public …Run Code Online (Sandbox Code Playgroud) 如果您拥有自己的数据库和BAL(业务访问层)并且不想使用DefaultConnection模板ASPNET数据库表但我自己的用户表怎么办?
你如何使用自定义数据库?
的ConnectionString:
public class AppDbContext : IdentityDbContext<AppUser>
{
public AppDbContext() : base("DefaultConnection")
{
}
}
Run Code Online (Sandbox Code Playgroud)
Web.config文件
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\v11.0;
AttachDbFilename=|DataDirectory|\NakedIdentity-Mvc.mdf;
Initial Catalog=NakedIdentity-Mvc;Integrated Security=True"
providerName="System.Data.SqlClient" />
Run Code Online (Sandbox Code Playgroud)