Ver Mensaje Individual
  #4 (permalink)  
Antiguo 31/07/2009, 12:31
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 18 años, 4 meses
Puntos: 126
Respuesta: Como codificar un pass antes de guardarlo en la db

Hola

Usa estas funciones

Código asp:
Ver original
  1. Dim Base64Chars
  2. Base64Chars ="Aa0Bb1Cc2Dd3Ee4Ff5Gg6Hh7IiJ8jKk9LlMmNnOoPpQqRrSsTtUuVvWwXxYyZz+/"
  3.                
  4. Public Function Codificar(byVal str)
  5. Dim c1, c2, c3, w1, w2, w3, w4, i, strIn, strOut
  6. strIn = Trim(str)
  7. For i = 1 To Len(strIn) Step 3
  8. c1 = Asc(Mid(strIn, i, 1))
  9. c2 = Asc(Mid(strIn, i + 1, 1) + Chr(0))
  10. c3 = Asc(Mid(strIn, i + 2, 1) + Chr(0))
  11. w1 = Int(c1 / 4) : w2 = (c1 And 3) * 16 + Int(c2 / 16)
  12. If Len(strIn) >= i + 1 Then
  13. w3 = (c2 And 15) * 4 + Int(c3 / 64)
  14. Else
  15. w3 = -1
  16. End If
  17. If Len(strIn) >= i + 2 Then
  18. w4 = c3 And 63
  19. Else
  20. w4 = -1
  21. End If
  22. strOut = strOut + aplCodificar(w1) + aplCodificar(w2) + aplCodificar(w3) + aplCodificar(w4)
  23. Next
  24. Codificar = strOut
  25. End Function
  26.  
  27. Private Function aplCodificar(byVal intIn)
  28. If intIn >= 0 Then
  29. aplCodificar = Mid(Base64Chars, intIn + 1, 1)
  30. Else
  31. aplCodificar = ""
  32. End If
  33. End Function
  34.  
  35. Public Function DeCodificar(byVal str)
  36. Dim w1, w2, w3, w4, i, strIn, strOut
  37. strIn = Trim(str)
  38. For i = 1 To Len(strIn) Step 4
  39. w1 = aplDeCodificar(Mid(strIn, i, 1))
  40. w2 = aplDeCodificar(Mid(strIn, i + 1, 1))
  41. w3 = aplDeCodificar(Mid(strIn, i + 2, 1))
  42. w4 = aplDeCodificar(Mid(strIn, i + 3, 1))
  43. If w2 >= 0 Then strOut = strOut + Chr(((w1 * 4 + Int(w2 / 16)) And 255))
  44. If w3 >= 0 Then strOut = strOut + Chr(((w2 * 16 + Int(w3 / 4)) And 255))
  45. If w4 >= 0 Then strOut = strOut + Chr(((w3 * 64 + w4) And 255))
  46. Next
  47. DeCodificar = strOut
  48. End Function
  49.  
  50. Private Function aplDeCodificar(byVal strIn)
  51. If Len(strIn) = 0 Then
  52. aplDeCodificar = -1 : Exit Function
  53. Else
  54. aplDeCodificar = InStr(Base64Chars, strIn) - 1
  55. End If
  56. End Function

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />