Guest User

PassGen source

a guest
Jan 19th, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.05 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <stdlib.h>
  3. LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  4. BOOL CALLBACK EnumChildProc(HWND hWnd, LPARAM lParam);
  5. TCHAR szClassName[] = TEXT("PassGenWnd");
  6. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  7. {
  8.     HWND hWnd, hButton, hEdit, hStatic, hAbout;
  9.     MSG Msg;
  10.     WNDCLASSEX wcex;
  11.    
  12.     wcex.cbClsExtra = 0;
  13.     wcex.cbSize = sizeof(WNDCLASSEX);
  14.     wcex.cbWndExtra = 0;
  15.     wcex.hbrBackground = (HBRUSH) COLOR_WINDOW;
  16.     wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  17.     wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  18.     wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  19.     wcex.hInstance = hInstance;
  20.     wcex.lpfnWndProc = WndProc;
  21.     wcex.lpszClassName = szClassName;
  22.     wcex.lpszMenuName = NULL;
  23.     wcex.style = CS_HREDRAW | CS_VREDRAW;
  24.  
  25.     RegisterClassEx(&wcex);
  26.  
  27.     hWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, szClassName, TEXT("Secure Password Generator"), WS_VISIBLE | WS_SYSMENU, 100, 100, 300, 100, NULL, NULL, hInstance, NULL);
  28.     hButton = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Generate"), WS_VISIBLE | WS_CHILD, 190, 38, 100, 30, hWnd, NULL, hInstance, NULL);
  29.     hStatic = CreateWindowEx(0, TEXT("STATIC"), TEXT("If you decide to use one of these passwords, do not forget it!"), WS_VISIBLE | WS_CHILD, 0, 0, 290, 20, hWnd, NULL, hInstance, NULL);
  30.     hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""), WS_VISIBLE | WS_CHILD | ES_READONLY, 0, 20, 290, 20, hWnd, NULL, hInstance, NULL);
  31.     hAbout = CreateWindowEx(0, TEXT("STATIC"), TEXT("Made by Govind on Sythe.org"), WS_VISIBLE | WS_CHILD, 0, 40, 160, 20, hWnd, NULL, hInstance, NULL);
  32.     ShowWindow(hWnd, SW_SHOW);
  33.     EnumChildWindows(hWnd, EnumChildProc, MAKELPARAM(FALSE, 0));
  34.     UpdateWindow(hWnd);
  35.    
  36.     while(GetMessage(&Msg, NULL, 0, 0) > 0)
  37.     {
  38.         TranslateMessage(&Msg);
  39.         DispatchMessage(&Msg);
  40.     }
  41.     return Msg.wParam;
  42.  
  43. }
  44.  
  45.  
  46.  
  47. BOOL CALLBACK EnumChildProc(HWND hWnd, LPARAM lParam)
  48. {
  49.     HFONT hfDefault = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
  50.     SendMessage(hWnd, WM_SETFONT, (WPARAM) hfDefault, MAKELPARAM(FALSE, 0));
  51.     return TRUE;
  52. }
  53.  
  54. LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  55. {
  56.     PAINTSTRUCT ps;
  57.     switch(Msg)
  58.     {
  59.     case WM_CLOSE:
  60.         DestroyWindow(hWnd);
  61.         break;
  62.     case WM_COMMAND:
  63.         srand((unsigned)GetTickCount());
  64.         if((HWND)lParam==FindWindowEx(hWnd, 0, TEXT("BUTTON"), 0))
  65.         {
  66.             TCHAR szTable[] = TEXT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,.`~!@#$%^&*()_+=-;:[{]}\\|/\?<>\'\"");
  67.             int len = wcslen(szTable);
  68.             int pwlen = 12+rand()%6;
  69.             int i;
  70.             TCHAR newPass[19];
  71.             HWND hEdit = FindWindowEx(hWnd, 0, TEXT("EDIT"), 0);
  72.             for(i = 0; i < pwlen; i++)
  73.             {
  74.                 newPass[i] = szTable[rand()%len];
  75.             }
  76.             newPass[i] = 0;
  77.             SetWindowText(hEdit, newPass);
  78.         }
  79.         break;
  80.     case WM_DESTROY:
  81.         PostQuitMessage(0);
  82.         break;
  83.     case WM_PAINT:
  84.         BeginPaint(hWnd, &ps);
  85.         EnumChildWindows(hWnd, EnumChildProc, MAKELPARAM(FALSE, 0));
  86.         EndPaint(hWnd, &ps);
  87.         break;
  88.     default:
  89.         return DefWindowProc(hWnd, Msg, wParam, lParam);
  90.     }
  91.     return 0;
  92. }
Add Comment
Please, Sign In to add comment