Jump to content

ASP Binary to string


Recommended Posts

I have a simple login page that passes the username and password to a validation page.

The password is stored as Binary in an SLQ2000 DB

When I perform the check on the two strings

if BinaryToString = request.form("password") then valid=1

it always comes back as valid=0 :(

if you display the two values they are the same.

I suspect there are control chars on the end of the string.

Can anyone help please.

<html>
<%

Function BinaryToString(Binary,valid)
'SimpleBinaryToString converts binary data (VT_UI1 | VT_ARRAY Or MultiByte string)
'to a string (BSTR) using MultiByte VBS functions
Dim I, S
valid=0
For I = 1 To LenB(Binary)
S = S & Chr(AscB(MidB(Binary, I, 1)))
Next
BinaryToString = S
if BinaryToString = request.form("password") then valid=1

End Function


%>

<head>
<title>Validation</title>
</head>

<body>
<%

Dim conn2
Set conn2 = Server.CreateObject("ADODB.Connection")
conn2.Open "DSN=Serverdetails; User Id = Administrator; Password=******"

Sqlgetuser="select * from users where Username='" & request.form("username") & "'"
set rs = conn2.execute(sqlgetuser)

Dim temppass
Dim valid
valid=0

temppass = BinaryTostring(rs("password"),valid)

if rs.eof then
response.write("User " & request.form("username") & " not found!")
session("password") = ""
session("username") = ""
elseif valid=1 then
session("user") = request.form("username")
session("permissions") = rs("permissions")
Response.Redirect("/index.htm")
else
response.write("Password incorrect!")
session("password") = ""
session("username") = ""
end if


%>
</body>

</html>

Link to comment
Share on other sites


Im getting a little closer.

If I do

response.write(len(BinaryToString))
response.write(len(request.form("password")))

I get 50 and 8

If I do

response.write("B= " & Ascb(MidB(Binary, I, 1)) & " : ")
if len(request.form("password")) >= i then response.write("P = " & Ascb(MidB(trim(request.form("password")), I, 1)) & " | ")

I get

B= 112 : P = 112 | B= 97 : P = 0 | B= 115 : P = 97 | B= 115 : P = 0 | B= 119 : P = 115 | B= 111 : P = 0 | B= 114 : P = 115 | B= 100 : P=0 | B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 : B= 0 :

the password box is passing a null (or 0) value and the binary string has trailing nulls (or 0's)

Sorted :thumbup

My solution

Ive changed

S = S & Chr(AscB(MidB(Binary, I, 1)))

to

if Chr(AscB(MidB(Binary, I, 1))) <> Chr(0) then
S = S & Chr(AscB(MidB(Binary, I, 1)))
end if

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...