MVC 3,其中加密用户的密码? [英] MVC 3 where to encrypt the user's password?

查看:220
本文介绍了MVC 3,其中加密用户的密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我使用来检查用户的密码登录时我自己的密码加密DLL,这是在我的用户实体引用。

I have my own password encryption dll that I am using to check the user's password when they login, this is referenced in my User entity.

现在我已经创建了一个用户注册是从密码尚未被加密做工精细,除了能力。

Now I have created the ability for a user to register which is working fine, apart from the passwords are yet to be encrypted.

我的问题很简单,在这里我应该把新用户的密码加密?我不知道,因为我知道,用户的密码不应该以纯文本格式进行传输,所以我不知道在哪里最好的地方调用加密功能:

My question is quite simple, where should I put the encryption of the new user's password? I'm not sure as I am aware that the user's password shouldn't be transmitted in plain text, therefore I don't know where the best place to call the encryption function:


  • 用户实体(如加密DLL已用于验证)。

  • 用户资料库,其中保存用户的方法是。

  • 用户控制器,用户创建视图控制。

  • 别的地方,我还没有考虑!

非常感谢

推荐答案

首先,客户端 - 服务器的通信,我会建议你使用SSL的敏感信息(如密码)不得以纯文本格式传输

First of all, for client - server communication, I would suggest you to use SSL for the sensitive information (like passwords) not to be transferred in plain text format.

之后,它是常见的做法不是在任何地方保存密码(即使是加密的,但其中的哈希值。

Afterwards, it's the common practice not to save passwords anywhere (even with encryption, but the hashed values of them.

您可以把散列函数密码属性的设置方法。下面是一个例子:

You can put the hash function to the set method of password property. Here is an example:

public class Member
{
    private string _username;

    public string Username
    {
        get { return _username; }
        set { _username = value.ToLowerInvariant(); }
    }

    public string Passhash {get;set;}

    public void SetPassword(string password)
    {
        Passhash = Crypto.Hash(password);
    }

    public bool CheckPassword(string password)
    {
        return string.Equals(Passhash, Crypto.Hash(password));
    }
}

public static class Crypto
{
    public static string Hash(string value)
    {
        return Convert.ToBase64String(
            System.Security.Cryptography.SHA256.Create()
            .ComputeHash(Encoding.UTF8.GetBytes(value)));
    }
}

编辑:

正如克雷格斯顿茨指出的那样,在本实施例的哈希code是很简单的。请参阅以下职位哈希密码更安全的方式:<一href=\"http://stackoverflow.com/questions/4329909/hashing-passwords-with-md5-or-sha-256-c-sharp\">Hashing与MD5或SHA-256 C#密码

As Craig Stuntz pointed out, the Hash code in this example is very simple. See the following post for a more secure way to hash your password: Hashing passwords with MD5 or sha-256 C#

这篇关于MVC 3,其中加密用户的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆