Click here to Skip to main content
15,889,808 members
Articles / Programming Languages / C++

Winlogon using Mobile Disk

Rate me:
Please Sign up or sign in to vote.
4.83/5 (25 votes)
30 Nov 2007CPOL6 min read 136.4K   2.6K   89  
This is a full set of applications that can be used to logon to Windows system using mobile disk. No password typing.
// KeyGenDlg.cpp : implementation file
//

#include "stdafx.h"
#include "KeyGen.h"
#include "KeyGenDlg.h"
#include "SelectUserDlg.h"
#include "GetUserInfoDlg.h"
#include "SelectDrive.h"
#include "..\UserInfo.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CKeyGenDlg dialog

CKeyGenDlg::CKeyGenDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CKeyGenDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CKeyGenDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CKeyGenDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CKeyGenDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CKeyGenDlg, CDialog)
	//{{AFX_MSG_MAP(CKeyGenDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_KEY_GEN_BUTTON, GenerateKey)
	ON_BN_CLICKED(IDC_CHECK_USER_BUTTON, OnCheckUserButton)
	ON_BN_CLICKED(IDC_VALID_DISK_QRY_BUTTON, OnValidDiskQryButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CKeyGenDlg message handlers

BOOL CKeyGenDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CKeyGenDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CKeyGenDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

HCURSOR CKeyGenDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CKeyGenDlg::GenerateKey() 
{

	USER_INFO user_info;
	CUserInfo ui;

	char lpDrive[5], lpPath[100];

	CGetUserInfoDlg dlg;

	if(IDCANCEL==dlg.DoModal())
		return;

	strcpy(user_info.lpWindowsUser,(LPCSTR)dlg.m_szUserName);
	strcpy(user_info.lpWindowsPassword,(LPCSTR)dlg.m_szPassword);
	strcpy(user_info.lpDomain,(LPCSTR)dlg.m_szDomain);

	strcpy(user_info.lpUserName, (LPCSTR)dlg.m_szUserName);
	strcpy(user_info.lpPassword,(LPCSTR)dlg.m_szKey);

	if(dlg.m_nLogonType==0)
	{
		strcpy(user_info.lpWindowsUser,(LPCSTR)"Guest");
		strcpy(user_info.lpWindowsPassword,(LPCSTR)"");
	}

	user_info.dwLogonType=dlg.m_nLogonType;

	sprintf(lpDrive,"%c:\\",'A'+dlg.m_nDrive);

	char	szVolName[MAX_PATH], szSysName[MAX_PATH];

	DWORD	dwVolSerialNumber, dwMaxComponentLen, dwFileSysFlags;


	szVolName[0]=0;


	GetVolumeInformation(lpDrive ,
						szVolName, MAX_PATH, 
						&dwVolSerialNumber,
						&dwMaxComponentLen, &dwFileSysFlags, 
						szSysName, MAX_PATH );



	strcpy(user_info.lpFileSystem,szSysName);
	strcpy(user_info.lpVolName,szVolName);
	
	user_info.dwMagic=ui.GetRandomMagic();

	user_info.dwVolSerialNo=dwVolSerialNumber;


	user_info=ui.Encode(user_info);

	sprintf(lpPath,"%s%s",lpDrive,DISK_FILE_NAME);
	
	if(!ui.CreateDiskFile(user_info,lpPath))
		MessageBox("Disk file can not be created\t","Error",MB_OK|MB_ICONSTOP);
	else
		MessageBox("Disk creation successfull\t","Success",MB_OK|MB_ICONINFORMATION);
}

void CKeyGenDlg::OnCheckUserButton() 
{
//	ShowWindow(SW_HIDE);
	char lpPath[20];

	CUserInfo ui;

	CSelectDrive drv;
	if(IDCANCEL==drv.DoModal())
	{	
		ShowWindow(SW_SHOW);
		return;
	}

	sprintf(lpPath,"%c:\\%s",'A'+drv.m_nDrive, DISK_FILE_NAME);

	USER_INFO user_info=ui.LoadUserInfo(lpPath);

	
	user_info=ui.Decode(user_info);

	//ui.Print(user_info);

	if(!ui.CheckDisk(user_info,drv.m_nDrive))
		MessageBox("Disk verification failed\t","Error",MB_OK|MB_ICONSTOP);
	else
		MessageBox("Disk verification successfull\t","Success",MB_OK|MB_ICONINFORMATION);

}

void CKeyGenDlg::OnOK() 
{
	// TODO: Add extra validation here
	
//	CDialog::OnOK();
}

void CKeyGenDlg::OnCancel() 
{
	// TODO: Add extra cleanup here

	CDialog::OnCancel();
}

void CKeyGenDlg::OnValidDiskQryButton() 
{

	CUserInfo ui;

	int x=ui.ValidDiskPresent();

	if(x)
	{
		char lpMsg[100];
		sprintf(lpMsg,"Valid user information found on [%c:]\t",'A'+x);

		MessageBox(lpMsg,"Success",MB_OK|MB_ICONINFORMATION);
	}

	else
		MessageBox("No valid disk found\t","Error",MB_OK|MB_ICONSTOP);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Microsoft
United States United States
Have completed BSc in Computer Science & Engineering from Shah Jalal University of Science & Technology, Sylhet, Bangladesh (SUST).

Story books (specially Masud Rana series), tourism, songs and programming is most favorite.

Blog:
Maruf Notes
http://blog.kuashaonline.com

Comments and Discussions