Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
1.7 KiB

  1. /* Copyright (c) 1994, Microsoft Corporation, all rights reserved
  2. **
  3. ** pwutil.c
  4. ** Remote Access
  5. ** Password handling routines
  6. **
  7. ** 03/01/94 Steve Cobb
  8. */
  9. #include <windows.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #define INCL_PWUTIL
  13. #include <ppputil.h>
  14. #define PASSWORDMAGIC 0xA5
  15. VOID ReverseString( CHAR* psz );
  16. CHAR*
  17. DecodePw(
  18. IN CHAR chSeed,
  19. IN OUT CHAR* pszPassword )
  20. /* Un-obfuscate 'pszPassword' in place.
  21. **
  22. ** Returns the address of 'pszPassword'.
  23. */
  24. {
  25. return EncodePw( chSeed, pszPassword );
  26. }
  27. CHAR*
  28. EncodePw(
  29. IN CHAR chSeed,
  30. IN OUT CHAR* pszPassword )
  31. /* Obfuscate 'pszPassword' in place to foil memory scans for passwords.
  32. **
  33. ** Returns the address of 'pszPassword'.
  34. */
  35. {
  36. if (pszPassword)
  37. {
  38. CHAR* psz;
  39. ReverseString( pszPassword );
  40. for (psz = pszPassword; *psz != '\0'; ++psz)
  41. {
  42. if (*psz != chSeed)
  43. *psz ^= chSeed;
  44. /*
  45. if (*psz != (CHAR)PASSWORDMAGIC)
  46. *psz ^= PASSWORDMAGIC;
  47. */
  48. }
  49. }
  50. return pszPassword;
  51. }
  52. VOID
  53. ReverseString(
  54. CHAR* psz )
  55. /* Reverses order of characters in 'psz'.
  56. */
  57. {
  58. CHAR* pszBegin;
  59. CHAR* pszEnd;
  60. for (pszBegin = psz, pszEnd = psz + strlen( psz ) - 1;
  61. pszBegin < pszEnd;
  62. ++pszBegin, --pszEnd)
  63. {
  64. CHAR ch = *pszBegin;
  65. *pszBegin = *pszEnd;
  66. *pszEnd = ch;
  67. }
  68. }
  69. CHAR*
  70. WipePw(
  71. IN OUT CHAR* pszPassword )
  72. /* Zero out the memory occupied by a password.
  73. **
  74. ** Returns the address of 'pszPassword'.
  75. */
  76. {
  77. if (pszPassword)
  78. {
  79. CHAR* psz = pszPassword;
  80. while (*psz != '\0')
  81. *psz++ = '\0';
  82. }
  83. return pszPassword;
  84. }