🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #3829

ASP: Strings vergelijken / Encryptie

#3829
From: Mathias Vissers
Date: Mon, 13 Oct 2003 17:12
123 lines
4551 bytes
Hallo allemaal,

ik houd in een database een ledenlijst samen met paswoorden, zodat mensen
online kunnen inloggen via een website. Ze kunnen ervoor kiezen dat hun
paswoord bewaard blijft in een cookie, zodat ze automatisch worden ingelogd
in de toekomst. Ik heb nu een functie geschreven die dit paswoord gecodeerd
bewaard. Zie hieronder de functie voor coderen en decoderen:



Private Function EncryptString(strString)

Dim CharHexSet, intStringLen, strTemp, strRAW, i, intKey, intOffSet
Randomize Timer

intKey = Round((RND * 1000000) + 1000000)   '##### Key Bitsize
intOffSet = Round((RND * 1000000) + 1000000)   '##### KeyOffSet Bitsize

 If IsNull(strString) = False Then
  strRAW = strString
  intStringLen = Len(strRAW)

    For i = 0 to intStringLen - 1
     strTemp = Left(strRAW, 1)
     strRAW = Right(strRAW, Len(strRAW) - 1)
     CharHexSet = CharHexSet & Hex(Asc(strTemp) * intKey) & Hex(intKey)
    Next

  EncryptString = CharHexSet & "|" & Hex(intOffSet + intKey) & "|" &
Hex(intOffSet)
 Else
  EncryptString = ""
 End If
End Function




Private Function DeCryptString(strCryptString)

Dim strRAW, arHexCharSet, i, intKey, intOffSet, strRawKey, strHexCrypData


 strRawKey = Right(strCryptString, Len(strCryptString) -
InStr(strCryptString, "|"))
 intOffSet = Right(strRawKey, Len(strRawKey) - InStr(strRawKey,"|"))
 intKey = HexConv(Left(strRawKey, InStr(strRawKey, "|") - 1)) -
HexConv(intOffSet)
 strHexCrypData = Left(strCryptString, Len(strCryptString) - (Len(strRawKey)
+ 1))


 arHexCharSet = Split(strHexCrypData, Hex(intKey))

  For i=0 to UBound(arHexCharSet)
   strRAW = strRAW & Chr(HexConv(arHexCharSet(i))/intKey)
  Next

 DeCryptString = strRAW
End Function



Private Function HexConv(hexVar)
Dim hxx, hxx_var, multiply
  IF hexVar <> "" THEN
   hexVar = UCASE(hexVar)
   hexVar = StrReverse(hexVar)
   DIM hx()
   REDIM hx(LEN(hexVar))
   hxx = 0
   hxx_var = 0
   FOR hxx = 1 TO LEN(hexVar)
    IF multiply = "" THEN multiply = 1
    hx(hxx) = mid(hexVar,hxx,1)
    hxx_var = (get_hxno(hx(hxx)) * multiply) + hxx_var
    multiply = (multiply * 16)
   NEXT
   hexVar = hxx_var
   HexConv = hexVar
  END IF
End Function

Private Function get_hxno(ghx)
  If ghx = "A" Then
   ghx = 10
  ElseIf ghx = "B" Then
   ghx = 11
  ElseIf ghx = "C" Then
   ghx = 12
  ElseIf ghx = "D" Then
   ghx = 13
  ElseIf ghx = "E" Then
   ghx = 14
  ElseIf ghx = "F" Then
   ghx = 15
  End If
  get_hxno = ghx
End Function

%>




Dit werkt allemaal perfect. In de procedure voor auto-login, wordt er
nagekeken of het paswoord in de database gelijk is aan het paswoord van de
cookie. Hier zit het probleem nu net. Om ��n of andere reden wilt ASP niet
aannemen dat de twee strings gelijk zijn aan elkaar. Ik heb al geprobeerd
met een gewone = alsook met de functie StrComp(). Telkens blijkt dat de twee
strings verschillend zijn. Echter wanneer ik ga testen met een
response.write, en ik laat de twee strings op scherm verschijnen, zijn deze
identiek dezelfde! Ik kan er alleszinds niet meer aan uit... Iemand een
voorstel?

dim pasw
    pasw = DeCryptString(request.cookies("login")("paswoord"))
    if pasw = lgs("paswoord") then
     session("log") = lgs("userid")
     query = "INSERT INTO online2 (userid, SID, login) VALUES (" &
Session("log") & "," & Session.SessionID & ",#" & now() & "#)"
     conn.Execute (query)
    end if
Technical Details
Message-ID: <G1Bib.75590$jy.3786780@phobos.telenet-ops.be>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!skynet.be!skynet.be!skynet.be!skynet.be!ossa.telenet-ops.be!phobos.telenet-ops.be.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII
X-Google-Thread: 107324,fe91a88aa49dc8ff,start
X-Google-Attributes: gid107324,public
X-Google-Thread: fcea4,fe91a88aa49dc8ff,start
X-Google-Attributes: gidfcea4,public
X-Google-ArrivalTime: 2003-10-13 10:12:08 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!skynet.be!skynet.be!skynet.be!skynet.be!ossa.telenet-ops.be!phobos.telenet-ops.be.POSTED!not-for-mail
From: "Mathias Vissers" <matje008@hotmail.com>
Newsgroups: be.comp.programming,nl.comp.programmeren
Subject: ASP: Strings vergelijken / Encryptie
Lines: 125
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <G1Bib.75590$jy.3786780@phobos.telenet-ops.be>
Date: Mon, 13 Oct 2003 17:12:06 GMT
NNTP-Posting-Host: 213.118.87.9
X-Complaints-To: abuse@telenet.be
X-Trace: phobos.telenet-ops.be 1066065126 213.118.87.9 (Mon, 13 Oct 2003 19:12:06 MEST)
NNTP-Posting-Date: Mon, 13 Oct 2003 19:12:06 MEST
Organization: Telenet Internet