// MBPwdPolicyMgr.cpp : implementation file
|
//
|
|
#include "stdafx.h"
|
#include "mbcore.h"
|
#include "MBPwdPolicyMgr.h"
|
|
|
// CMBPwdPolicyMgr
|
#define INI_PWDCONFIGFILE _T( "PwdPolicyCfg.ini" )
|
|
#define APPSET_PWD_SECTION _T("APPSET_PWD")
|
#define APPSET_PWD_SECTION_USEPOLICY _T("UsePwdPolicy") //ʹÓÃÃÜÂë²ßÂÔ
|
#define APPSET_PWD_SECTION_MINLEN _T("PwdMinLen") //ÃÜÂë×îС³¤¶È£¬Ä¬ÈÏÊÇ6
|
#define APPSET_PWD_SECTION_HAVENUMBER _T("PwdHaveNumber")//ÊÇ·ñÓÐÊý×Ö£¬1´ú±í±ØÐëÓУ¬0´ú±íÓÐûÓж¼¿ÉÒÔ£¬ ĬÈϱØÐëÓÐ0
|
#define APPSET_PWD_SECTION_HAVECHAR _T("PwdHaveChar")//ÊÇ·ñÓÐ×Öĸ£¬1´ú±í±ØÐëÓУ¬0´ú±íÓÐûÓж¼¿ÉÒÔ£¬ ĬÈϱØÐëÓÐ0
|
#define APPSET_PWD_SECTION_HAVELOWERCASE _T("PwdHaveLowerCase") //ÊÇ·ñÓÐСд×Öĸ£¬1´ú±í±ØÐëÓУ¬0´ú±íÓÐûÓж¼¿ÉÒÔ£¬ ĬÈϱØÐëÓÐ0
|
#define APPSET_PWD_SECTION_HAVEUPPERCASE _T("PwdHaveUpperCase") //ÊÇ·ñÓдóд×Öĸ£¬1´ú±í±ØÐëÓУ¬0´ú±íÓÐûÓж¼¿ÉÒÔ£¬ ĬÈϱØÐëÓÐ0
|
#define APPSET_PWD_SECTION_HAVESPECCHAR _T("PwdHaveSpecChar")//ÊÇ·ñÓÐÌØÊâ×Ö·û£¬1´ú±í±ØÐëÓУ¬0´ú±íÓÐûÓж¼¿ÉÒÔ£¬ ĬÈϱØÐëÓÐ0
|
|
CMBPwdPolicyMgr::CMBPwdPolicyMgr()
|
{
|
}
|
|
CMBPwdPolicyMgr::~CMBPwdPolicyMgr()
|
{
|
}
|
|
|
// CMBPwdPolicyMgr member functions
|
CString CMBPwdPolicyMgr::GetIniFile()
|
{
|
CString strFileName;
|
|
strFileName.Format( _T("%s\\Data\\%s"),CBaseCommFun:: GetWorkDir() , INI_PWDCONFIGFILE );
|
return strFileName;
|
}
|
BOOL CMBPwdPolicyMgr::IsUsePwdPolicy( )
|
{
|
CString strInitFile;
|
DWORD dwValue = 0;
|
strInitFile = GetIniFile();
|
dwValue = GetPrivateProfileInt(APPSET_PWD_SECTION, APPSET_PWD_SECTION_USEPOLICY,0, strInitFile );
|
if ( dwValue == 0 )
|
{
|
return FALSE;
|
}
|
else
|
return TRUE;
|
}
|
|
//========================================
|
// £¬Ä¬ÈÏÊÇ6
|
//========================================
|
int CMBPwdPolicyMgr::GetPwdMinLen( )
|
{
|
CString strInitFile;
|
DWORD dwValue = 0;
|
strInitFile = GetIniFile();
|
dwValue = GetPrivateProfileInt(APPSET_PWD_SECTION, APPSET_PWD_SECTION_MINLEN,6, strInitFile );
|
if(dwValue < 0)
|
dwValue = 0;
|
else if(dwValue > 32)
|
dwValue = 32;
|
return dwValue;
|
}
|
|
//========================================
|
// ÊÇ·ñÓÐÊý×Ö£¬1´ú±í±ØÐëÓУ¬0´ú±íÓÐûÓж¼¿ÉÒÔ£¬ ĬÈϱØÐëÓÐ0
|
//========================================
|
BOOL CMBPwdPolicyMgr::IsPwdHaveNumber( )
|
{
|
CString strInitFile;
|
DWORD dwValue = 0;
|
strInitFile = GetIniFile();
|
dwValue = GetPrivateProfileInt(APPSET_PWD_SECTION, APPSET_PWD_SECTION_HAVENUMBER,0, strInitFile );
|
if ( dwValue == 0 )
|
{
|
return FALSE;
|
}
|
else
|
return TRUE;
|
}
|
|
//========================================
|
// ÊÇ·ñÓÐ×Öĸ£¬1´ú±í±ØÐëÓУ¬0´ú±íÓÐûÓж¼¿ÉÒÔ£¬ ĬÈϱØÐëÓÐ0
|
//========================================
|
BOOL CMBPwdPolicyMgr::IsPwdHaveChar( )
|
{
|
CString strInitFile;
|
DWORD dwValue = 0;
|
strInitFile = GetIniFile();
|
dwValue = GetPrivateProfileInt(APPSET_PWD_SECTION, APPSET_PWD_SECTION_HAVECHAR,0, strInitFile );
|
if ( dwValue == 0 )
|
{
|
return FALSE;
|
}
|
else
|
return TRUE;
|
}
|
//========================================
|
// ÊÇ·ñÓÐСд×Öĸ£¬1´ú±í±ØÐëÓУ¬0´ú±íÓÐûÓж¼¿ÉÒÔ£¬ ĬÈϱØÐëÓÐ0
|
//========================================
|
BOOL CMBPwdPolicyMgr::IsPwdHaveLowerCase( )
|
{
|
CString strInitFile;
|
DWORD dwValue = 0;
|
strInitFile = GetIniFile();
|
dwValue = GetPrivateProfileInt(APPSET_PWD_SECTION, APPSET_PWD_SECTION_HAVELOWERCASE,0, strInitFile );
|
if ( dwValue == 0 )
|
{
|
return FALSE;
|
}
|
else
|
return TRUE;
|
}
|
|
//========================================
|
// ÊÇ·ñÓдóд×Öĸ£¬1´ú±í±ØÐëÓУ¬0´ú±íÓÐûÓж¼¿ÉÒÔ£¬ ĬÈϱØÐëÓÐ0
|
//========================================
|
BOOL CMBPwdPolicyMgr::IsPwdHaveUpperCase( )
|
{
|
CString strInitFile;
|
DWORD dwValue = 0;
|
strInitFile = GetIniFile();
|
dwValue = GetPrivateProfileInt(APPSET_PWD_SECTION, APPSET_PWD_SECTION_HAVEUPPERCASE,0, strInitFile );
|
if ( dwValue == 0 )
|
{
|
return FALSE;
|
}
|
else
|
return TRUE;
|
}
|
|
//========================================
|
// ÊÇ·ñÓÐÌØÊâ×Ö·û£¬1´ú±í±ØÐëÓУ¬0´ú±íÓÐûÓж¼¿ÉÒÔ£¬ ĬÈϱØÐëÓÐ0
|
//========================================
|
BOOL CMBPwdPolicyMgr::IsPwdHaveSpecChar( )
|
{
|
CString strInitFile;
|
DWORD dwValue = 0;
|
strInitFile = GetIniFile();
|
dwValue = GetPrivateProfileInt(APPSET_PWD_SECTION, APPSET_PWD_SECTION_HAVESPECCHAR,0, strInitFile );
|
if ( dwValue == 0 )
|
{
|
return FALSE;
|
}
|
else
|
return TRUE;
|
}
|
BOOL CMBPwdPolicyMgr::CheckUserPasswordPolicy(CString strPassword,CString &strErrorInfo)
|
{
|
strErrorInfo = _T("");
|
int nPwdMinLen = GetPwdMinLen( );
|
BOOL bIsPwdHaveNumber = IsPwdHaveNumber( );
|
BOOL bIsPwdHaveChar = IsPwdHaveChar( );
|
BOOL bIsPwdHaveUpperCase = IsPwdHaveUpperCase( );
|
BOOL bIsPwdHaveLowerCase = IsPwdHaveLowerCase( );
|
BOOL bIsPwdHaveSpecChar = IsPwdHaveSpecChar( );
|
if(strPassword.GetLength() < nPwdMinLen || strPassword.GetLength() > 32)
|
{
|
CString strTemp;
|
strTemp.Format( _T("ÃÜÂ볤¶È²»¶ÌÓÚ%dºÍ³¤ÓÚ32") ,nPwdMinLen);
|
return FALSE;
|
}
|
BOOL bCheckNumber = FALSE;
|
BOOL bIsCheckChar = FALSE;
|
BOOL bIsCheckUpperCase = FALSE;
|
BOOL bIsCheckLowerCase = FALSE;
|
BOOL bIsCheckSpecChar = FALSE;
|
if(bIsPwdHaveNumber)
|
{
|
bCheckNumber = TRUE;
|
}
|
if(bIsPwdHaveChar)
|
{
|
bIsCheckChar = TRUE;
|
if(bIsPwdHaveUpperCase)
|
{
|
bIsCheckUpperCase = TRUE;
|
}
|
if(bIsPwdHaveLowerCase)
|
{
|
bIsCheckLowerCase = TRUE;
|
}
|
}
|
if(bIsPwdHaveSpecChar)
|
{
|
bIsCheckSpecChar = TRUE;
|
}
|
int nLen = strPassword.GetLength();
|
TCHAR chTemp;
|
for(int i= 0; i < nLen;i++)
|
{
|
chTemp = strPassword.GetAt(i);
|
if(bCheckNumber)
|
{
|
if(chTemp >= _T('0')&&chTemp <= '9')
|
{
|
bCheckNumber = FALSE;
|
}
|
}
|
if(bIsCheckUpperCase)
|
{
|
if(chTemp >= _T('A')&&chTemp <= 'Z')
|
{
|
bIsCheckUpperCase = FALSE;
|
}
|
}
|
if(bIsCheckLowerCase)
|
{
|
if(chTemp >= _T('a')&&chTemp <= 'z')
|
{
|
bIsCheckLowerCase = FALSE;
|
}
|
}
|
if(bIsCheckChar)
|
{
|
if((chTemp >= _T('a')&&chTemp <= 'z') || (chTemp >= _T('a')&&chTemp <= 'z'))
|
{
|
bIsCheckChar = FALSE;
|
}
|
}
|
if(bIsCheckSpecChar)
|
{
|
if((chTemp >= _T('!')&&chTemp < '0') || (chTemp > _T('9')&&chTemp < 'A')
|
|| (chTemp > _T('Z')&&chTemp < 'a') || (chTemp > _T('z')&&chTemp <= '~'))
|
{
|
bIsCheckSpecChar = FALSE;
|
}
|
}
|
|
}
|
if(bCheckNumber || bIsCheckChar|| bIsCheckSpecChar)
|
{
|
CString strTemp = _T("");
|
strErrorInfo.Format(_T("ÃÜÂëÊdz¤¶È²»ÉÙÓÚ%d룬±ØÐ뺬ÓÐ"),nPwdMinLen);
|
if(bIsPwdHaveNumber)
|
strTemp = _T("Êý×Ö¡¢");
|
strErrorInfo+= strTemp;
|
strTemp = _T("");
|
if(bIsPwdHaveChar)
|
{
|
strTemp = _T("×Öĸ¡¢");
|
if(bIsPwdHaveUpperCase || bIsPwdHaveLowerCase)
|
{
|
if( bIsPwdHaveUpperCase)
|
{
|
strTemp = _T(" ´óд×Öĸ¡¢");
|
strErrorInfo+= strTemp;
|
}
|
if( bIsPwdHaveLowerCase)
|
{
|
strTemp = _T(" Сд×Öĸ¡¢");
|
strErrorInfo+= strTemp;
|
}
|
}
|
else
|
strErrorInfo+= strTemp;
|
}
|
strTemp = _T("");
|
if(bIsPwdHaveSpecChar)
|
strTemp = _T("ÌØÊâ×Ö·û¡¢");
|
strErrorInfo+= strTemp;
|
strErrorInfo.TrimRight(_T("¡¢"));
|
strErrorInfo+= _T("µÄ×Ö·û´®");
|
return FALSE;
|
}
|
return TRUE;
|
}
|