使用GetHashCode方法的问题 [英] Problem in using GetHashCode method

查看:74
本文介绍了使用GetHashCode方法的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用GetHashCode()来加密密码字段.
创建新用户时,用户输入的密码将存储在hascode值中,例如

I have used GetHashCode() to encrypt password field.
When new user is created the password entered by user is stored in hascode value like

string pswd = txtPassword.text.GetHashCode();



然后将此pswd字符串存储在数据库中.之后,当用户登录到他的帐户时,我再次将用户输入的值转换为hascode值,例如



then this pswd string is stored in database. After that when user login to his account then again I convert user''s entered value in hascode value like

string userPassword = txtEnterPassword.text.GetHashcode();



然后,我检查保存在数据库中的密码的值和用户的文本是否匹配.在我的开发服务器上可以正常工作.

但是,当我将此页面上传到实时服务器时,它无法正常工作.用户创建新帐户后,他尝试使用正确的密码登录,则无法登录该页面.

我在msdn中搜索了解决方案,然后阅读了以下这一行:"GetHashCode方法的默认实现不能保证不同对象的唯一返回值."现在我该怎么办.



Then I check the value of the password saved in database and user''s text is matching or not. This working fine in my development server.

But when I uploaded this page in live server it''s not working. When user create new account and after that he try to login with his correct password he cannot login to the page.

I searched the solution in msdn then I read this line: ''The default implementation of the GetHashCode method does not guarantee unique return values for different objects.'' What I should to do now. Please anyone have any idea?

推荐答案

您最好的选择就是不要那样做.请参阅以下代码项目资源,以了解如何解决密码加密问题:

密码存储:操作方法. [分形加密算法 [ The Art&存储密码的科学 [ ^ ]
Your best bet is not to do it that way. See these code project resources for how you can approach your password encryption issues:

Password Storage: How to do it.[^]
Fractal encryption algorithm[^]
The Art & Science of Storing Passwords[^]


好吧,您可以覆盖并提供自己的GetHashCode(),也可以使用MD5根据输入的值生成哈希.

此链接讨论GetHashCode():链接GHC [链接MD5 [ ^ ]

PS:过去,我已经成功地使用MD5来根据用户输入值生成哈希,然后将该哈希存储为加密"密码.
Well, either you can override and provide your own GetHashCode() or you can use MD5 to generate a hash based on the value input.

This link talks about GetHashCode(): Link GHC[^]

and this link talks about MD5: Link MD5[^]

PS: I have used MD5 in the past with reasonable success to generate a hash based on the user input value and then store this hash as an "encrypted" password.


我进行了搜索msdn中的解决方案,然后我读到这一行:"GetHashCode方法的默认实现不能保证不同对象的唯一返回值."
这不是这里的问题.我相信这只是意味着2个不同的对象可以具有相同的哈希值(不是唯一的),反之亦然,这是您要担心的.
I searched the solution in msdn then I read this line: ''The default implementation of the GetHashCode method does not guarantee unique return values for different objects.''
That is not going to be the issue here. I believe this just means that 2 different objects can have the same hash value (not unique), not vice versa, which is your concern.


这篇关于使用GetHashCode方法的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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