Forum Moderators: mack

Message Too Old, No Replies

Help solving a 500 Error in password hashing code

         

studeggle

2:51 pm on Apr 14, 2004 (gmt 0)



I am trying to get my asp program to save the passwords in hash form to make them more secure, but I keep getting a HTTP 500 error (I don't have access to error logs to see exactly what is wrong)


<!--#include file="dsn.asp"-->
<%
If Request("Create") <> "" Then
if Len(Request("Admin_Password")) >= 8 Then
If Request("Admin_Password") = Request("Password2") Then
' Generate random salt (10 characters)
Randomize
Salt = ""
For i = 1 to 10
'65 is ASCII for "A"
Salt = Salt & chr(int(Rnd * 26) + 65)
Next

' Calculate Hash of (Admin_Password & Salt)
Set CM = Server.CreateObject("Persits.CryptoManager")
Set Context = CM.OpenContext("mycontainer", True)
Set Hash = Context.CreateHash
Hash.AddText Request("Admin_Password") & Salt
HashValue = Hash.Value.Hex
Set Hash = Nothing
Set CM = Nothing

' Save username, hashed value and salt in the database
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "Settings", "DSN=crypto;UID=sa;PWD=;", 2, 3
RS.addnew
RS("Admin_ID").Value = Request("Admin_ID")
RS("Admin_Password").Value = HashValue
RS("salt").Value = Salt
RS.update
RS.close
Set RS = Nothing

Response.Write "Account was successfully created."
Else
Response.Write "Password was not correctly confirmed."
End If
Else
Response.Write "Password must be at least 8 characters."
End If
End If
%>
<FORM ACTION="AddUser.asp" METHOD="POST">
<TABLE><TR>
<TD>Username:</TD>
<TD><INPUT TYPE="TEXT" NAME="Admin_ID" VALUE="<% = Request("Admin_ID") %>" size="20"></TD>
</TR><TR>
<TD>Password:</TD><TD>
<INPUT TYPE="PASSWORD" NAME="Admin_Password" size="20"></TD>
</TR><TR>
<TD>Confirm Password:</TD>
<TD><INPUT TYPE="PASSWORD" NAME="Password2" size="20"></TD>
</TR><TR>
<TD COLSPAN=2><INPUT TYPE="Submit" NAME="Create" VALUE="Create Account"></TD>
</TR></TABLE></FORM>
<!--#include file="dsn2.asp"-->

Short passwords, and incorrectly confirmed passwords generate the correct rejection statment, so I know it is in the salt generating, or password hashing part of the code. Does anyone have any idea what could be cuasing my error?

isitreal

3:05 pm on Apr 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Why don't you try posting this question in the Microsoft/Asp forum [webmasterworld.com], I think you'll get better help there.

Krapulator

4:12 am on Apr 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you uncheck "Show Friendly HTTP Errors" in IE's advanced options, you will get a detailed error message that should point you in the right direction.