0
|
1 // Filename : auth.cpp
|
4
|
2 // Last Change: 2018-10-12 金 16:17:32.
|
0
|
3 //
|
|
4
|
4
|
5 #include "id.h"
|
0
|
6 #include "auth.h"
|
|
7
|
|
8 AuthDialog::AuthDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
|
|
9 : wxDialog( parent, id, title, pos, size, style )
|
|
10 {
|
|
11 CreateControls();
|
|
12 }
|
|
13
|
|
14 AuthDialog::~AuthDialog()
|
|
15 {
|
|
16 }
|
|
17
|
|
18 // Event Table
|
|
19 BEGIN_EVENT_TABLE( AuthDialog, wxDialog )
|
3
|
20 EVT_SHOW( AuthDialog::OnShow )
|
0
|
21 EVT_TEXT( ID_UID, AuthDialog::OnCheckUserID )
|
|
22 EVT_TEXT( ID_PW, AuthDialog::OnCheckPassword )
|
|
23 EVT_TEXT_ENTER( ID_UID, AuthDialog::OnEnter )
|
|
24 EVT_TEXT_ENTER( ID_PW, AuthDialog::OnEnter )
|
3
|
25 EVT_BUTTON( wxID_OK, AuthDialog::OnEnter )
|
0
|
26 END_EVENT_TABLE()
|
|
27
|
|
28 // Event Handler
|
3
|
29 void AuthDialog::OnShow( wxShowEvent& WXUNUSED(event) )
|
|
30 {
|
|
31 if ( m_load ) return;
|
|
32 wxArrayString args; // http get ( auth.db, hhs.db, index.db )
|
|
33 args.Add( wxT( "client.exe" ) );
|
|
34 args.Add( wxT( "-u" ) );
|
|
35 args.Add( m_server );
|
|
36
|
|
37 wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE );
|
|
38
|
|
39 wxTextFile file;
|
|
40 file.Open( wxT( "auth.db" ) );
|
|
41 for ( int i = 0; i < file.GetLineCount(); i++ ) {
|
|
42 wxArrayString line = wxSplit( file.GetLine( i ), ' ', '\\' );
|
|
43 m_users.Add( line[ 0 ] );
|
|
44 }
|
|
45 file.Close();
|
|
46
|
|
47 m_load = true;
|
|
48 }
|
|
49
|
0
|
50 void AuthDialog::OnCheckUserID( wxCommandEvent& WXUNUSED(event) )
|
|
51 {
|
|
52 wxString id = m_textCtrlId->GetValue();
|
3
|
53 for ( int i = 0; i < m_users.GetCount(); i++ ) {
|
|
54 if ( id.IsSameAs( m_users[ i ], true ) ) {
|
|
55 m_staticTextIdmsg->SetLabel( wxT( "ok" ) );
|
|
56 m_staticTextPwmsg->SetLabel( wxT( "← input" ) );
|
|
57 m_textCtrlPw->SetValue( wxEmptyString );
|
|
58 m_textCtrlPw->SetFocus();
|
|
59 return;
|
|
60 } else {
|
|
61 m_staticTextIdmsg->SetLabel( wxT( "← input" ) );
|
|
62 m_staticTextPwmsg->SetLabel( wxEmptyString );
|
|
63 }
|
|
64 }
|
0
|
65 }
|
|
66
|
|
67 void AuthDialog::OnCheckPassword( wxCommandEvent& WXUNUSED(event) )
|
|
68 {
|
|
69 wxString pw = m_textCtrlPw->GetValue();
|
|
70 if ( pw.Len() < 4 ) {
|
3
|
71 m_staticTextPwmsg->SetLabel( wxT( "← too short" ) );
|
0
|
72 }
|
|
73 else {
|
|
74 m_staticTextPwmsg->SetLabel( wxEmptyString );
|
|
75 }
|
|
76 }
|
|
77
|
|
78 void AuthDialog::OnEnter( wxCommandEvent& WXUNUSED(event) )
|
|
79 {
|
3
|
80 m_staticTextPwmsg->SetLabel( wxEmptyString );
|
|
81 if ( IsValidUser() ) {
|
|
82 m_user = m_textCtrlId->GetValue();
|
|
83 EndModal( wxID_OK );
|
|
84 }
|
|
85 m_staticTextPwmsg->SetLabel( wxT( "Bad User/Password !!" ) );
|
|
86 m_textCtrlPw->SelectAll();
|
|
87 return;
|
0
|
88 }
|
|
89
|
|
90 // Functions
|
|
91 void AuthDialog::CreateControls( void )
|
|
92 {
|
|
93 this->SetIcon( wxIcon( wxT( "sample" ) ) );
|
|
94 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
|
|
95 this->SetBackgroundColour( wxColour( 0, 150, 230 ) );
|
|
96
|
|
97 wxGridSizer* gSizer = new wxGridSizer( 0, 3, 0, 0 );
|
|
98
|
|
99 // user id
|
3
|
100 m_staticTextId = new wxStaticText( this, wxID_ANY, wxT( "User ID" ), wxDefaultPosition, wxDefaultSize, 0 );
|
0
|
101 gSizer->Add( m_staticTextId, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 );
|
|
102
|
|
103 m_textCtrlId = new wxTextCtrl( this, ID_UID, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
|
|
104 gSizer->Add( m_textCtrlId, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
105
|
|
106 m_staticTextIdmsg = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
|
107 m_staticTextIdmsg->SetForegroundColour( wxColour( 250, 0, 0 ) );
|
|
108 gSizer->Add( m_staticTextIdmsg, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
109
|
|
110 // password
|
3
|
111 m_staticTextPw = new wxStaticText( this, wxID_ANY, wxT( "Password" ), wxDefaultPosition, wxDefaultSize, 0 );
|
0
|
112 gSizer->Add( m_staticTextPw, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 );
|
|
113
|
|
114 m_textCtrlPw = new wxTextCtrl( this, ID_PW, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD|wxTE_PROCESS_ENTER );
|
|
115 gSizer->Add( m_textCtrlPw, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
116
|
|
117 m_staticTextPwmsg = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
|
118 m_staticTextPwmsg->SetForegroundColour( wxColour( 250, 0, 0 ) );
|
|
119 gSizer->Add( m_staticTextPwmsg, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
3
|
120
|
|
121 // buttons
|
|
122 gSizer->AddSpacer( 1 );
|
|
123
|
|
124 m_buttonLogin = new wxButton( this, wxID_OK, wxT( "Login" ), wxDefaultPosition, wxDefaultSize, 0 );
|
|
125 gSizer->Add( m_buttonLogin, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
126
|
|
127 m_buttonCancel = new wxButton( this, wxID_CANCEL, wxT( "Cancel" ), wxDefaultPosition, wxDefaultSize, 0 );
|
|
128 gSizer->Add( m_buttonCancel, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
129
|
0
|
130
|
|
131 this->SetSizer( gSizer );
|
|
132 this->Layout();
|
|
133 gSizer->Fit( this );
|
|
134
|
|
135 this->Centre( wxBOTH );
|
3
|
136 m_textCtrlId->SetFocus();
|
0
|
137 }
|
|
138
|
3
|
139 bool AuthDialog::IsValidUser( void )
|
|
140 {
|
|
141 wxString id = m_textCtrlId->GetValue();
|
|
142 wxString pw = m_textCtrlPw->GetValue();
|
|
143
|
|
144 wxArrayString args;
|
|
145 args.Add( wxT( "crypto.exe" ) );
|
|
146 args.Add( wxT( "-c" ) );
|
|
147 args.Add( wxT( "auth.db" ) );
|
|
148 args.Add( wxT( "-s" ) );
|
|
149 args.Add( wxT( "@#!;" ) ); // salt
|
|
150 args.Add( id );
|
|
151 args.Add( pw );
|
|
152
|
|
153 int ret = wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE );
|
|
154 if ( ret == 39 ) return true;
|
|
155
|
|
156 return false;
|
|
157 }
|
|
158
|
|
159 void AuthDialog::InDevelop( bool flag )
|
|
160 {
|
4
|
161 return;
|
3
|
162 if ( !flag ) return;
|
|
163 m_textCtrlId->SetValue( "test" );
|
|
164 m_textCtrlPw->SetValue( "test" );
|
|
165 m_textCtrlPw->SetFocus();
|
|
166 }
|
|
167
|