简体   繁体   English

如何使用MVC Entity Framework代码优先方法加密和解密密码以存储数据库?

[英]How to encrypt and decrypt password to store DB in MVC Entity Framework Code First Approach?

How to Encrypt and decrypt Password to store db in MVC Entity Framework? 如何加密和解密密码以在MVC实体框架中存储数据库? Am using Following Code.Please anyone Help Me. 我正在使用以下代码。请任何人帮助我。

      [Required]
    [StringLength(15, MinimumLength = 8)]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

Best practice is not to encrypt/decrypt the password, you should hash it (and salt it) 最佳做法是不对密码进行加密/解密,您应该对密码进行哈希处理 (并对其加盐)

  • User signs up > hash password > store hash to DB 用户注册>哈希密码>将哈希存储到数据库

  • User logs in > hash password > compare to stored hash in DB 用户登录>哈希密码>比较数据库中存储的哈希

This makes the password difficult to recreate if an attacker gets a hold of it. 如果攻击者掌握了密码,这将使密码难以重新创建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM