Пример #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            ResetWindow();

            // If there is no username entered.
            if (tbxUsername.Text == "")
            {
                lblUsername.ForeColor = Color.Red;
                tbxUsername.ForeColor = Color.Red;
                lblResult.ForeColor   = Color.Red;
                lblResult.Text        = "You did not enter a username.";
                return;
            }

            // If there is no password entered.
            if (tbxPassword.Text == "")
            {
                lblPassword.ForeColor = Color.Red;
                tbxPassword.ForeColor = Color.Red;
                lblResult.ForeColor   = Color.Red;
                lblResult.Text        = "You did not enter a password.";
                return;
            }

            btnLogin.Enabled     = false;
            btnRegister.Enabled  = false;
            tbxUsername.ReadOnly = true;
            tbxPassword.ReadOnly = true;

            lblResult.Text        = "Contacting server...";
            _waitingForLoginReply = true;
            byte[] passwordHash = ByteHelper.GetHashBytes(Encoding.Unicode.GetBytes(tbxPassword.Text));
            ChatTwo_Client_Protocol.MessageToServer(ChatTwo_Protocol.MessageType.Login, passwordHash, tbxUsername.Text);
            timer1.Start();
        }
Пример #2
0
 private static string CreateMac(byte[] messageBytes, string sharedSecret)
 {
     return(ByteHelper.GetHashString(ByteHelper.ConcatinateArray(ByteHelper.GetHashBytes(messageBytes), Convert.FromBase64String(sharedSecret))));
 }
Пример #3
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            ResetWindow();

            // If there is no username entered.
            if (tbxUsername.Text == "")
            {
                lblUsername.ForeColor = Color.Red;
                tbxUsername.ForeColor = Color.Red;
                lblResult.ForeColor   = Color.Red;
                lblResult.Text        = "You did not enter a username.";
                return;
            }

            // If the username is too long.
            if (tbxUsername.Text.Length > 30)
            {
                lblUsername.ForeColor = Color.Red;
                tbxUsername.ForeColor = Color.Red;
                lblResult.ForeColor   = Color.Red;
                lblResult.Text        = "The username is too long. Please use 30 or less characters.";
                return;
            }

            // If there is no password entered.
            if (tbxPassword1.Text == "")
            {
                lblPassword1.ForeColor = Color.Red;
                tbxPassword1.ForeColor = Color.Red;
                lblResult.ForeColor    = Color.Red;
                lblResult.Text         = "You did not enter a password.";
                return;
            }

            // If the password and the confirm password textboxes aren't the same.
            if (tbxPassword1.Text != tbxPassword2.Text)
            {
                lblPassword2.ForeColor = Color.Red;
                tbxPassword2.ForeColor = Color.Red;
                lblResult.ForeColor    = Color.Red;
                lblResult.Text         = "The two passwords are not the same.";
                return;
            }

            // If the password is too short.
            // (I hate strict password rules! If it is not a bank or social security thing, don't force the uesr to make insane passwords.)
            if (tbxPassword1.Text.Length < 4)
            {
                lblPassword1.ForeColor = Color.Red;
                tbxPassword1.ForeColor = Color.Red;
                lblResult.ForeColor    = Color.Red;
                lblResult.Text         = "The password is too short. Please use 4 or more characters.";
                return;
            }

            btnRegister.Enabled   = false;
            btnCancel.Enabled     = false;
            tbxUsername.ReadOnly  = true;
            tbxPassword1.ReadOnly = true;
            tbxPassword2.ReadOnly = true;

            lblResult.Text             = "Contacting server...";
            _waitingForCreateUserReply = true;
            byte[] passwordHash = ByteHelper.GetHashBytes(Encoding.Unicode.GetBytes(tbxPassword1.Text));
            ChatTwo_Client_Protocol.MessageToServer(ChatTwo_Protocol.MessageType.CreateUser, passwordHash, tbxUsername.Text);
            timer1.Start();
        }