Results 1 to 8 of 8

Thread: Encryption / Hashing method which can be used in PHP AND VB for my passwords?

  1. #1

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Encryption / Hashing method which can be used in PHP AND VB for my passwords?

    hey ya,

    Does any one know a Sub Function / Routine, which i can use for PHP and VB which will both give the exact same result?

    Say in php:
    PHP Code:
    $password "My Password Here";
    $hased_pass = function($password); 
    and vb:

    VB Code:
    1. Dim HasedPass as string
    2. HashedPass = Module1.Function("My Password Here")

    ..? cuz i need to encrypt my users password / hash em, so as to protect there Data,

    But i need to be able to use the same password in my website, and in my Chat Server application....
    Wayne

  2. #2
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    Use MD5

    vbMD5 module Is attached


    Heres a way to use MD5 in PHP

    PHP Code:

    <html> 
    <head> 
    <!--coded by harsha email:[email protected]
    <title>php and its md5 function</title> 
    <?php 
    /*if statement  verifies the form input*/  
    if($HTTP_POST_VARS

    $codemd5($pass);   
    /*note that these htmlspecialchars and md5 are the built in functons of php language*/ 
    echo "the word you have entered is:\t\t\t".$pass."<br>"
    echo 
    "the md5ied form of the word is:\t\t\t".$code

    //end of if statement 
    ?> 
    </head> 
    <body> 
    <form method="post" action="<?=$PHP_SELF?>"> 
    <br> 
    <b>enter a word:</b><br><input type="text" name="pass"><br> 
    <input type="submit" value="md5"> 
    </form> 
    </body> 
    </html>

    -I did not write the PHP or VB Examples


    Incase you are not familar with MD5, you can not decrypt it
    you must encrypt the password that the user types in and then compare it with the stored password.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  3. #3

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    they give difference results though?

    IE:

    Text1 in php gives: 8fd6355c54556be287fecb4166c4a8c1
    Text1 in VB gives: 8d993394c892dcaa8683dc4ba4fae21d

    [i have searched the forums for ages, even asked a thread b4 about md5, but their diff, etc.]

    Is there any way i can get any encryption to give the same result? or will i need to result to having a normal text password in my DB?

    [Not that much of a problem, except that it exposes ppl's passwords if ma site gets hacked some way etc..]

    How bout a base64_encode? [not "Perfect" but its still some "Protection"?]

    is there a way to do this in php/vb that gives the same result?
    [This is just a type of "Encoding/Encryption" for php. its used alot for my cookies etc, so it isnt normal text in cookies that ne 1 can read...]

    thanks....
    Wayne

  4. #4
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    And about the MD5, I've checked your MD5 output with one of my MD5 algorithm that I made from this http://www.ietf.org/rfc/rfc1321.txt, and it seems that from the 2 hash strings that you pasted, the VB one is the correct one...
    As I know, in PHP, you can include ActiveX DLL's (I think), if that's true, then, you can make a DLL in VB, using the same algorithm that you use in VB (the one you pasted)... Like that you'll have the same result always...




    Base64 is te easyest encryption to break because it does not use any password to encode it...

    VB Code:
    1. Public Function Base64Encoding(StrToEncode As String) As String
    2.     Static EncodeTable(0 To 63) As Byte
    3.    
    4.     Dim K As Long, OutStr() As Byte, StrIn() As Byte, Lng As Long
    5.    
    6.     If EncodeTable(0) = 0 Then
    7.         For K = 0 To 25
    8.             EncodeTable(K) = Asc("A") + K
    9.         Next K
    10.        
    11.         For K = 0 To 25
    12.             EncodeTable(K + 26) = Asc("a") + K
    13.         Next K
    14.        
    15.         For K = 0 To 9
    16.             EncodeTable(K + 52) = Asc("0") + K
    17.         Next K
    18.        
    19.         EncodeTable(62) = Asc("+")
    20.         EncodeTable(63) = Asc("/")
    21.     End If
    22.    
    23.     If StrToEncode = "" Then Exit Function
    24.    
    25.     StrIn = StrConv(StrToEncode, vbFromUnicode)
    26.     If (Len(StrToEncode) Mod 3) = 0 Then
    27.         ReDim OutStr((Len(StrToEncode) \ 3) * 4 - 1)
    28.     Else
    29.         ReDim OutStr(((Len(StrToEncode) \ 3) + 1) * 4 - 1)
    30.     End If
    31.    
    32.     For K = 0 To Len(StrToEncode) \ 3 - 1
    33.         Lng = StrIn(K * 3 + 2) Or (StrIn(K * 3 + 1) * &H100&) Or (StrIn(K * 3) * &H10000)
    34.        
    35.         OutStr(K * 4 + 0) = EncodeTable((Lng And &HFC0000) \ &H40000)
    36.         OutStr(K * 4 + 1) = EncodeTable((Lng And &H3F000) \ &H1000&)
    37.         OutStr(K * 4 + 2) = EncodeTable((Lng And &HFC0&) \ &H40&)
    38.         OutStr(K * 4 + 3) = EncodeTable(Lng And &H3F&)
    39.     Next K
    40.    
    41.     If (Len(StrToEncode) Mod 3) = 1 Then
    42.         Lng = StrIn(UBound(StrIn)) * &H10000
    43.        
    44.         OutStr(UBound(OutStr) - 3) = EncodeTable((Lng And &HFC0000) \ &H40000)
    45.         OutStr(UBound(OutStr) - 2) = EncodeTable((Lng And &H3F000) \ &H1000&)
    46.         OutStr(UBound(OutStr) - 1) = Asc("=")
    47.         OutStr(UBound(OutStr) - 0) = Asc("=")
    48.     ElseIf (Len(StrToEncode) Mod 3) = 2 Then
    49.         Lng = (StrIn(UBound(StrIn)) * &H100&) Or (StrIn(UBound(StrIn) - 1) * &H10000)
    50.        
    51.         OutStr(UBound(OutStr) - 3) = EncodeTable((Lng And &HFC0000) \ &H40000)
    52.         OutStr(UBound(OutStr) - 2) = EncodeTable((Lng And &H3F000) \ &H1000&)
    53.         OutStr(UBound(OutStr) - 1) = EncodeTable((Lng And &HFC0&) \ &H40&)
    54.         OutStr(UBound(OutStr) - 0) = Asc("=")
    55.     End If
    56.    
    57.     Base64Encoding = StrConv(OutStr, vbUnicode)
    58. End Function
    59.  
    60. Public Function Base64Decoding(StrToDecode As String, Optional CheckInvalidChars As Boolean = True) As String
    61.     Static DecodeTable(0 To 255) As Byte
    62.    
    63.     Dim OutStr() As Byte, StrIn() As Byte
    64.     Dim K As Long, Lng As Long
    65.    
    66.     If DecodeTable(0) = 0 Then
    67.         For K = 0 To 255
    68.             DecodeTable(K) = 255
    69.         Next K
    70.        
    71.         For K = 0 To 25
    72.             DecodeTable(K + 65) = K
    73.         Next K
    74.        
    75.         For K = 26 To 51
    76.             DecodeTable(K + 71) = K
    77.         Next K
    78.        
    79.         For K = 52 To 61
    80.             DecodeTable(K - 4) = K
    81.         Next K
    82.        
    83.         DecodeTable(43) = 62
    84.         DecodeTable(47) = 63
    85.     End If
    86.    
    87.     If StrToDecode = "" Then Exit Function
    88.    
    89.     StrToDecode = Trim(StrToDecode)
    90.    
    91.     If CheckInvalidChars Then
    92.         For K = 0 To 255
    93.             If Not (Chr(K) Like "[A-Za-z0-9+/=]") Then
    94.                 StrToDecode = Replace(StrToDecode, Chr(K), "")
    95.             End If
    96.         Next K
    97.     End If
    98.    
    99.     StrIn() = StrConv(StrToDecode, vbFromUnicode)
    100.     ReDim OutStr(0 To ((Len(StrToDecode) \ 4) * 3 - 1))
    101.    
    102.     For K = 0 To Len(StrToDecode) \ 4 - 2
    103.         Lng = DecodeTable(StrIn(K * 4 + 3))
    104.         Lng = Lng Or (DecodeTable(StrIn(K * 4 + 2)) * &H40&)
    105.         Lng = Lng Or (DecodeTable(StrIn(K * 4 + 1)) * &H1000&)
    106.         Lng = Lng Or (DecodeTable(StrIn(K * 4 + 0)) * &H40000)
    107.        
    108.         OutStr(K * 3 + 0) = (Lng And &HFF0000) \ &H10000
    109.         OutStr(K * 3 + 1) = (Lng And &HFF00&) \ &H100&
    110.         OutStr(K * 3 + 2) = Lng And &HFF&
    111.     Next K
    112.    
    113.     Lng = 0
    114.     If DecodeTable(StrIn(K * 4 + 3)) <> 255 Then Lng = DecodeTable(StrIn(K * 4 + 3))
    115.     If DecodeTable(StrIn(K * 4 + 2)) <> 255 Then Lng = Lng Or (DecodeTable(StrIn(K * 4 + 2)) * &H40&)
    116.     If DecodeTable(StrIn(K * 4 + 1)) <> 255 Then Lng = Lng Or (DecodeTable(StrIn(K * 4 + 1)) * &H1000&)
    117.     If DecodeTable(StrIn(K * 4 + 0)) <> 255 Then Lng = Lng Or (DecodeTable(StrIn(K * 4 + 0)) * &H40000)
    118.    
    119.     OutStr(K * 3 + 0) = (Lng And &HFF0000) \ &H10000
    120.     OutStr(K * 3 + 1) = (Lng And &HFF00&) \ &H100&
    121.     OutStr(K * 3 + 2) = Lng And &HFF&
    122.    
    123.     If StrIn(UBound(StrIn) - 1) = 61 Then
    124.         Base64Decoding = Left(StrConv(OutStr, vbUnicode), UBound(OutStr) - 1)
    125.     ElseIf StrIn(UBound(StrIn)) = 61 Then
    126.         Base64Decoding = Left(StrConv(OutStr, vbUnicode), UBound(OutStr) - 0)
    127.     Else
    128.         Base64Decoding = StrConv(OutStr, vbUnicode)
    129.     End If
    130. End Function

  5. #5

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    OK, I'll try and see about makin the Active X DLL For PHP.

    tnx :
    Wayne

  6. #6

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    lol, dont suppose u no how i load the dll into php when its made?
    Wayne

  7. #7
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Nope... no clue... don't even know if it's possible, that was just in theory...

    Post a question in PHP forum to ask for this...

  8. #8
    Member
    Join Date
    Oct 2005
    Posts
    48

    Re: Encryption / Hashing method which can be used in PHP AND VB for my passwords?

    Hi ,i have got a program to encryp files using RC4 ,normaly i use rc4 to encode ,and after i use Base64Encoding ,to save in a binary file ,but the files are very large ,and sometimes ,if the file is long i recive a message ,telling that there isn't enought memory.

    Does anybody know any sugestion ,to a best encode?

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width