使用soui开发的mbc,只支持windows版本
w1146869587
2022-01-24 0408576e9da10015ffa9da0079b8c985113ce4b3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
// 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;
}