コード例 #1
0
    }//end method RunServer
    
    // When click on login button
    private void btn_Login_Click(object sender, EventArgs e)
    {
        //Save in variables text values on fields
        string username = txt_Username.Text;
        string password = txt_Password.Text;
        
        //regex for validation text fields
        string regFormat = @"^[a-zA-Z0-9.]{5,20}$";
        Regex reg = new Regex(regFormat);
        
        Match matchUsername = reg.Match(username);
        Match matchPassword = reg.Match(password);

        //Is validate successfully username
        if (!matchUsername.Success)
        {
            lbl_ErrorMSGUsername.Text = "Your username is too short!";
            lbl_ErrorMSGPassword.Text = "";
        }
        //Is validate successfully password
        else if (!matchPassword.Success)
        {
            lbl_ErrorMSGPassword.Text = "Your password is too short!";
            lbl_ErrorMSGUsername.Text = "";
        }
        else
        {
            // clear error messages
            lbl_ErrorMSGPassword.Text = "";   
            lbl_ErrorMSGUsername.Text = "";
            Users users = (Users)Easy.load("users.xml");

            if (users.Username == username && users.Password == password)
            {
                var win = new BankCards();
                win.Show();
            }
            else
            {
                Users user = new Users(username, password);
                String filename = "users.xml";
                Easy.save(user, filename);
                var win = new BankCards();
                win.Show();
            }
        }
    } // end method btn_Login_Click