SQL Server的varbinary数据类型可以存储哪些数据?
我有一个表,其中 userpassword 字段具有 varbinary 数据类型,所以我很困惑应该以哪种形式将数据保存到 userpassword 字段中,因为当我保存 varchar 数据时,它给了我错误。
I have a table in which the userpassword field have varbinary datatype, So I'm confused that in which form should I save the data into userpassword field because when I save varchar data it gave me error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
varbinary
列可以存储任何内容。要在其中存储字符串,您必须将其转换为varbinary
:但对于密码,
varbinary
列通常存储某种哈希值。例如,使用的 SHA1 哈希HashBytes
函数:存储单向哈希而不是真实密码更安全。您可以检查密码是否匹配:
但是您无法通过查看表来检索密码。因此只有最终用户知道他的密码,甚至 DBA 也无法检索它。
A
varbinary
column can store anything. To store a string in it, you'd have to cast it tovarbinary
:But for a password, a
varbinary
column usually stores a hash of some kind. For example, a SHA1 hash using theHashBytes
function:Storing a one-way hash instead of the real password is more secure. You can check if the password matches:
But there is no way you can retrieve the password by looking at the table. So only the end user knows his password, and not even the DBA can retrieve it.
您需要显式转换 VARCHAR。
SQL Server 错误消息显示。
You will need to explicitly cast the VARCHAR.
SQL Server error message says.
SQL Server 需要从 varchar 到 varbinary,根据 MSDN 中 CAST 和 CONVERT 上的大表
该表将有一个 varbinary 列来存储哈希值,根据 sys.sql_logins
SQL Server requires an explicit conversion from varchar to varbinary, as per the big table on CAST and CONVERT in MSDN
The table will have a varbinary column to store hashed values as per sys.sql_logins
------你必须给它一个尺寸---------->
------you have to give it a size ---------->