Click here to Skip to main content
15,886,518 members
Articles / Programming Languages / C++

Login password filters in WinXP

Rate me:
Please Sign up or sign in to vote.
4.80/5 (16 votes)
25 May 2006CPOL6 min read 108.2K   2.6K   54  
An article on how to build login password filters on WinXP.
#include "StringExt.h"
//#include <afxtempl.h>

class regPathList : public StringExt
{
public:
	//Constructors
	regPathList()
	{
		mkey = NULL;
		keyPath = NULL;
	}
	regPathList(HKEY Root, char *Path)
	{
		if(!Path)return;
		SetPath(Root, Path);
	}
	~regPathList()
	{
		if(mkey)RegCloseKey(mkey);	
		if(keyPath)delete [] keyPath;
	}
	//adders
	void SetPath(HKEY Root, char *Path)
	{
		//Check parameters
		if(!Root)return;
		if(!Path)return;
		
		if(keyPath)delete[] keyPath;
		if(mkey)RegCloseKey(mkey);
		keyPath = new char [strlen(Path)+1];
		strcpy(keyPath, Path);
		RegCreateKeyEx(Root,keyPath,0,0,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,0,&mkey,0);//Process Error
	}
	void AddREG_DWORD(char *inName, DWORD inValue)
	{
		//Check parameters
		if(!inName)return;

		LONG resluts=0;
		resluts = RegSetValueEx(mkey, inName, NULL, REG_DWORD,(BYTE *)(&inValue),sizeof(DWORD));	
	}
	void AddREG_MULTI_SZ(char *inName, char *inValue,int inBehavior)
	{
		//Check parameters
		if(!inName)return;
		if(!inValue)return;

		DWORD ValueSize;
		DWORD NameSize;
		char *RegValueData=0;
		char *RegNameData=0;
		DWORD RegType;

		if(!mkey)return;
		RegQueryValueEx(mkey, inName,NULL,&RegType,NULL, &ValueSize);
			if( (ValueSize==0) || (inBehavior == WRITEOVER ) )
			{
				RegValueData = new char [strlen(inValue)+2];
					memcpy(RegValueData,inValue,strlen(inValue));
					RegValueData[strlen(inValue)]=0;
					RegValueData[strlen(inValue)+1]=0;
					RegSetValueEx(mkey, inName, NULL, REG_MULTI_SZ,(BYTE *)(RegValueData),2+strlen(inValue));
					delete [] RegValueData;}
			else
			{		
					RegValueData = new char [(strlen(inValue) + ValueSize +1)];
					RegQueryValueEx(mkey, inName,NULL,&RegType,(BYTE *)RegValueData, &ValueSize);
					memcpy((RegValueData + ValueSize-1), inValue,1+strlen(inValue));
					RegValueData[strlen(inValue) + ValueSize]='\0';
					RegSetValueEx(mkey, inName, NULL, REG_MULTI_SZ,(BYTE *)(RegValueData),(strlen(inValue) + ValueSize +1));
					delete [] RegValueData;					
			}		
	}
	void AddREG_SZ(char *inName, char *inValue,int inBehavior)
	{
		//check parameters
		if(!inName)return;
		if(inValue)return;

		DWORD ValueSize;
		DWORD NameSize;
		char *RegValueData=0;
		char *RegNameData=0;
		DWORD RegType;

		if(!mkey)return;
		RegQueryValueEx(mkey, inName,NULL,&RegType,NULL, &ValueSize);
			if( (ValueSize==0) || (inBehavior == WRITEOVER ) )
			{
				RegSetValueEx(mkey, inName, NULL, REG_SZ,(BYTE *)inValue,1+strlen(inValue));
			}
			else
			{		
					RegValueData = new char [(strlen(inValue) + ValueSize +1)];
					RegQueryValueEx(mkey, inName,NULL,&RegType,(BYTE *)RegValueData, &ValueSize);
					memcpy((RegValueData + ValueSize-1), inValue,1+strlen(inValue));
					RegValueData[strlen(inValue) + ValueSize]='\0';
					RegSetValueEx(mkey, inName, NULL, REG_SZ,(BYTE *)(RegValueData),(strlen(inValue) + ValueSize +1));
					delete [] RegValueData;					
			}
	}
	void AddREG_EXPAND_SZ(char *inName, char *inValue,int inBehavior)
	{
		//Check parameters
		if(inName)return;
		if(inValue)return;
		
		DWORD ValueSize;
		DWORD NameSize;
		char *RegValueData=0;
		char *RegNameData=0;
		DWORD RegType;

		if(!mkey)return;
		RegQueryValueEx(mkey, inName,NULL,&RegType,NULL, &ValueSize);
			if( (ValueSize==0) || (inBehavior == WRITEOVER ) )
			{
				RegSetValueEx(mkey, inName, NULL, REG_EXPAND_SZ,(BYTE *)inValue,1+strlen(inValue));
			}
			else
			{		
					RegValueData = new char [(strlen(inValue) + ValueSize +1)];
					RegQueryValueEx(mkey, inName,NULL,&RegType,(BYTE *)RegValueData, &ValueSize);
					memcpy((RegValueData + ValueSize-1), inValue,1+strlen(inValue));
					RegValueData[strlen(inValue) + ValueSize]='\0';
					RegSetValueEx(mkey, inName, NULL, REG_EXPAND_SZ,(BYTE *)(RegValueData),(strlen(inValue) + ValueSize +1));
					delete [] RegValueData;					
			}
	}
	//removers
	void RemoveCurrentKey()
	{
		//HKEY *KeyChain = &mkey;
		//DWORD NameCount=0;
		//DWORD loop=0;
		//char **stack=0;
		//PFILETIME junkData;
		//char *NameKey;
		////
		//RegEnumKeyEx(KeyChain,loop,NULL,&NameCount,NULL,NULL,NULL,&junkData);
		//NameKey= new char [NameCount+1]
		//RegEnumKeyEx(KeyChain,loop,NameKey,&NameCount,NULL,NULL,NULL,&junkData);
		//
		//RegDeleteKey
		

	}
	void RemoveName(char *Name)
	{
		//Check parameters
		if(!Name)return;
		RegDeleteValue(mkey,Name);
	}
	void RemoveFromValue(char *in, char *in2)
	{
		//strstr
	}
	enum Behavior { WRITEOVER, APPEND};

	//Info Functions
	void GetParentKeyPath(char **KeyPath, size_t *SizeOfKeyPath)
	{
		char **KeyNamesSeperated = NULL;
		char *Seperator = "\\";
		int ListCount = SeperateStringBy(keyPath,Seperator,&KeyNamesSeperated) - 1;
		long TotalSizeOfPath;
		char *Temp=new char [1];
		if(!Temp)return;
		Temp[0]='\0';

		for(int loop=0; loop<ListCount;loop++)
		{
			AppendString( &Temp,KeyNamesSeperated[loop]);	
			AppendString(&Temp,Seperator);
		}
		if(SizeOfKeyPath)
			*(SizeOfKeyPath) = strlen(Temp);
		if(*(KeyPath))
			strcpy(*(KeyPath),Temp);
		if(Temp)delete [] Temp;
		if(KeyNamesSeperated)
		{
			for(int loop=0;loop<=ListCount;loop++)
			{ 
				if(KeyNamesSeperated[loop])
					delete [] KeyNamesSeperated[loop];
				
			}
			if(KeyNamesSeperated)
				delete KeyNamesSeperated;
		}
	}

	//helpers
private:
	HKEY mkey;
	char *keyPath;
};




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
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions