处理在 SQL Server 和经典 ASP 中存储为 varbinary 的哈希密码
各位,
提前抱歉 - 对于以下大多数主题(SQL、ASP),我都是新手。 无论如何......
我有一个非常简单的网络应用程序,要求用户使用用户名和密码登录。
前端创建密码的加盐 SHA1 哈希值,并将其(与用户名一起)发布到 ASP 页面。
该 ASP 页获取数据,调用 SQL Server 数据库中的存储过程,并传递用户名和散列密码; 存储过程将信息写入“用户”表。
表中密码列的类型是varbinary。
据我所知,当 ASP 获取密码(password = Request.Form("password"))时,它是一个字符串。
如果我这样创建查询,我可以“欺骗”SQL Server 将其作为 varbinary 处理:
query = "EXEC sp_save_user @username='" & 用户名和 "', @password=0x" & 密码
IOW - 我在密码字符串前面加上“0x”。
但是,我读到使用参数化查询是更好的做法:
例如: SET objParam = objCommand.CreateParameter("@password",204, 1, 40, password)
但是,这会失败,因为参数应该是二进制(204),但密码是字符串。
那么,如何将“4a5e6a8d521ed487b81c91e131cf27e8dae9b783”这样的字符串转换为 ASP 中的二进制文件?
提前谢谢了!
All,
Sorry in advance - I'm a novice in most of the topics below (SQL, ASP). Anyway...
I've got a pretty simple web app that requires users to log in with a user name and password.
The front end creates a salted SHA1 hash of the password, and posts it (along with the user's name) to an ASP page.
That ASP page takes the data, calls a stored procedure in the SQL Server database, and passes the users name and hashed password; the stored procedure writes the info to the 'users' table.
The password column's type in the table is varbinary.
As far as I can tell, when the ASP gets the password (password = Request.Form("password")), it's a String.
I can 'trick' SQL Server into handling it as a varbinary if I create the query this way:
query = "EXEC sp_save_user @username='" & username & "', @password=0x" & password
IOW - I'm prepending an "0x" to the password string.
However, I've read that it's a better practice to use a parameterized query:
E.g.: SET objParam = objCommand.CreateParameter("@password",204, 1, 40, password)
However, this fails because the parameter is supposed to be binary (204), but password is a string.
So, how do I convert a string like "4a5e6a8d521ed487b81c91e131cf27e8dae9b783" to a binary in ASP?
Many thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我记得那些日子我常常为这种事情敲头。 我建议您升级到 ASP.Net,但同时以下代码 (VBScript) 应该可以满足您的需求:
I remember the days when I used to bash my head on this kind of thing. I suggest you get an upgrade to ASP.Net, but in the mean time the following code (VBScript) should do what you want:
我假设您有范围更改数据库...更具体地说是存储过程?
为什么不直接接受散列作为字符串并将其 CAST 到 SProc 中的 varbinary ?
进一步阅读,没有内置 String -> SQL Server 中的 Varbinary 函数,但此函数作为一个简单的解决方案提供,
I assume you have scope to change the DB... more specifically the Stored Procedure?
Why not just accept the hash as a string and CAST it to varbinary within the SProc?
Reading further, there is no built-in String -> Varbinary function in SQL Server, but this function has been offered as an easy solution,
也许有点不相关,但我想知道,如果您在客户端上对哈希加盐,那么您到底如何保证盐的安全?
Maybe a bit unrelated, but I'm wondering, if you are salting the hash on the client, how are you exactly keeping the salt secure?