PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WEBDEV 2024 → PHP - SHA1 Issue
PHP - SHA1 Issue
Débuté par Mark, 25 juil. 2017 13:34 - 1 réponse
Posté le 25 juillet 2017 - 13:34
We're working on moving an existing site over from PHP/MySQL to AWP. We are having an issue with existing passwords which were encrypted using SHA1. The 60 character hex string in the password fields do not match what we're getting when we run the HashString function in the function below:

PROCEDURE SHA1HashStringToHex(LOCAL psStringToHash is string)
LOCAL
lbufHashed is Buffer
lcChar is character = ""
liPos is int = 0
liLen is int = 0
lsHexResult is string = ""
lbufHashed = HashString(HA_SHA_160, NoSpace(psStringToHash))
liLen = Length(lbufHashed)
FOR liPos = 1 TO liLen
lcChar = lbufHashed[[liPos]]
lsHexResult += NumToString(Asc(lcChar),"1x")
END
RESULT = lsHexResult

Thanks,
Mark
Posté le 25 juillet 2017 - 14:20
Hi Mark,

"1x"?

A character value goes from 0 to 255, so you should probably use 2x
instead, as the 1 gives you only ONE hex character in output.

or simply use buffertohexa instead of your loop

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Ready for you: WXShowroom.com, WXReplication (open source) and now WXEDM
(open source)

More information on http://www.fabriceharari.com


Le 7/25/2017 à 5:34 AM, Mark a écrit :
We're working on moving an existing site over from PHP/MySQL to AWP. We
are having an issue with existing passwords which were encrypted using
SHA1. The 60 character hex string in the password fields do not match
what we're getting when we run the HashString function in the function
below:

PROCEDURE SHA1HashStringToHex(LOCAL psStringToHash is string)
LOCAL
lbufHashed is Buffer lcChar is character = ""
liPos is int = 0
liLen is int = 0
lsHexResult is string = ""
lbufHashed = HashString(HA_SHA_160, NoSpace(psStringToHash))
liLen = Length(lbufHashed)
FOR liPos = 1 TO liLen lcChar = lbufHashed[[liPos]]
lsHexResult += NumToString(Asc(lcChar),"1x")
END
RESULT = lsHexResult

Thanks,
Mark