Ideas:
1. Read valid user name and password information from the configuration file
2. Obtain and match the username and password entered by the user in the window
1. Read valid user name and password information from the configuration file
Store the Information read from the configuration file to the userinfor * m_userlist; struct.
The configuration file format is as follows (@ separates the user name and password ):
Usercount = 2
Testusername1 @ testpassword1
1 @ 1
Const tchar configfile [max_path] = l "User configure.txt"; <br/> typedef tchar mtchar [max_path]; <br/> // storage struct <br/> userinfor * m_userlist; <br/> typedef struct userinfor <br/>{< br/> wchar username [max_path]; <br/> wchar password [max_path]; <br/> }; <br/> typedef tchar mtchar [max_path]; <br/> bool loadsettings () <br/>{< br/> file * fp = NULL; <br/> const int buflen = 1024; <br/> wchar Buf [buflen] = {0}; <br/> W Char content [max_path] = {0 }; <br/> int rst = 0; <br/> int vlen = 0; <br/> lptstr value = NULL; <br/> wchar flag; <br/> fp = _ wfopen (configfile, _ T ("R"); <br/> If (FP = NULL) <br/>{< br/> const char * error = "An error occurred while opening the file! "; <Br/> log (error, strlen (error); <br/> return false; <br/>}< br/> fgetws (BUF, buflen, FP); <br/> If (feof (FP) | swscanf (BUF, l "usercount = % d", & m_usercount )! = 1) <br/> m_usercount = 0; <br/> m_userlist = NULL; <br/> If (m_usercount> 0) <br/>{< br/> m_userlist = new userinfor [m_usercount]; <br/>}< br/> for (INT I = 0; I <m_usercount; I ++) <br/>{< br/> If (feof (FP) <br/> break; <br/> fgetws (BUF, buflen, FP ); <br/> wchar * P = wcschr (BUF, l' @ '); <br/> If (P! = NULL) <br/>{< br/> int n = wcslen (BUF ); <br/> If (BUF [n-1] = l'/N' | Buf [n-1] = l'/R ') <br/>{< br/> Buf [n-1] = l'/0'; <br/>}< br/> wcscpy (m_userlist [I]. password, p + 1); <br/> * P = l'/0'; <br/> wcscpy (m_userlist [I]. username, Buf); <br/>}< br/> else <br/>{< br/> const char * error = "Read File is blank! "; <Br/> log (error, strlen (error); <br/> return false; <br/>}< br/> fclose (FP); <br/> return true; <br/>}< br/>
2. Obtain and match the username and password entered by the user in the window
Void cauthdlg: onbnclickedloginin () <br/>{< br/> // todo: add the control notification handler code here <br/> updatedata (true ); <br/> If (m_username.getlength () <1 | m_password.getlength () <1) <br/>{< br/> MessageBox (L "Access Denied! "); <Br/> return; <br/>}< br/> int I = 0; <br/> mtchar username = {0 }; <br/> mtchar Password = {0}; <br/> wcscpy (username, m_username.getbuffer (m_username.getlength (); <br/> wcscpy (password, m_password.getbuffer (m_password.getlength (); <br/> for (I = 0; I <m_usercount; I ++) <br/>{< br/> If (wcscmp (m_userlist [I]. username, username) = 0 & wcscmp (m_userlist [I]. password, password) = 0) <br/>{< br/> break; <br />}< Br/> if (I = m_usercount) <br/>{< br/> MessageBox (L "Access Denied! "); <Br/> m_username = l" "; <br/> m_password = l" "; <br/> updatedata (false ); <br/>}< br/> else <br/>{< br/> oncancel (); <br/>}< br/>}