示例#1
0
        public void TrySendCode()
        {
            if (Globals.WaitingOnServer)
            {
                return;
            }

            if (!Networking.Network.Connected)
            {
                Interface.MsgboxErrors.Add(new KeyValuePair <string, string>("", Strings.Errors.notconnected));

                return;
            }

            if (string.IsNullOrEmpty(mCodeInputTextbox?.Text))
            {
                Interface.MsgboxErrors.Add(new KeyValuePair <string, string>("", Strings.ResetPass.inputcode));

                return;
            }

            if (mPasswordTextbox.Text != mPasswordTextbox2.Text)
            {
                Interface.MsgboxErrors.Add(new KeyValuePair <string, string>("", Strings.Registration.passwordmatch));

                return;
            }

            if (!FieldChecking.IsValidPassword(mPasswordTextbox.Text, Strings.Regex.password))
            {
                Interface.MsgboxErrors.Add(new KeyValuePair <string, string>("", Strings.Errors.passwordinvalid));

                return;
            }

            using (var sha = new SHA256Managed())
            {
                PacketSender.SendResetPassword(
                    Target, mCodeInputTextbox?.Text,
                    BitConverter.ToString(sha.ComputeHash(Encoding.UTF8.GetBytes(mPasswordTextbox.Text.Trim())))
                    .Replace("-", "")
                    );
            }

            Globals.WaitingOnServer = true;
            ChatboxMsg.ClearMessages();
        }
        public void TryLogin()
        {
            if (Globals.WaitingOnServer)
            {
                return;
            }

            if (!Networking.Network.Connected)
            {
                Interface.MsgboxErrors.Add(new KeyValuePair <string, string>("", Strings.Errors.notconnected));

                return;
            }

            if (!FieldChecking.IsValidUsername(mUsernameTextbox?.Text, Strings.Regex.username))
            {
                Interface.MsgboxErrors.Add(new KeyValuePair <string, string>("", Strings.Errors.usernameinvalid));

                return;
            }

            if (!FieldChecking.IsValidPassword(mPasswordTextbox?.Text, Strings.Regex.password))
            {
                if (!mUseSavedPass)
                {
                    Interface.MsgboxErrors.Add(new KeyValuePair <string, string>("", Strings.Errors.passwordinvalid));

                    return;
                }
            }

            var password = mSavedPass;

            if (!mUseSavedPass)
            {
                password = ComputePasswordHash(mPasswordTextbox?.Text?.Trim());
            }

            PacketSender.SendLogin(mUsernameTextbox?.Text, password);
            SaveCredentials();
            Globals.WaitingOnServer = true;
            mLoginBtn.Disable();
            ChatboxMsg.ClearMessages();
        }
        void TryRegister()
        {
            if (Globals.WaitingOnServer)
            {
                return;
            }

            if (Networking.Network.Connected)
            {
                if (FieldChecking.IsValidUsername(mUsernameTextbox.Text, Strings.Regex.username))
                {
                    if (mPasswordTextbox.Text == mPasswordTextbox2.Text)
                    {
                        if (FieldChecking.IsValidPassword(mPasswordTextbox.Text, Strings.Regex.password))
                        {
                            if (FieldChecking.IsWellformedEmailAddress(mEmailTextbox.Text, Strings.Regex.email))
                            {
                                Hide();

                                //Hash Password
                                using (var sha = new SHA256Managed())
                                {
                                    var hashedPass = BitConverter.ToString(
                                        sha.ComputeHash(Encoding.UTF8.GetBytes(mPasswordTextbox.Text.Trim()))
                                        )
                                                     .Replace("-", "");

                                    PacketSender.SendCreateAccount(
                                        mUsernameTextbox.Text, hashedPass, mEmailTextbox.Text
                                        );
                                }

                                Globals.WaitingOnServer = true;
                                mRegisterBtn.Disable();
                                ChatboxMsg.ClearMessages();
                            }
                            else
                            {
                                Interface.MsgboxErrors.Add(
                                    new KeyValuePair <string, string>("", Strings.Registration.emailinvalid)
                                    );
                            }
                        }
                        else
                        {
                            Interface.MsgboxErrors.Add(
                                new KeyValuePair <string, string>("", Strings.Errors.passwordinvalid)
                                );
                        }
                    }
                    else
                    {
                        Interface.MsgboxErrors.Add(
                            new KeyValuePair <string, string>("", Strings.Registration.passwordmatch)
                            );
                    }
                }
                else
                {
                    Interface.MsgboxErrors.Add(new KeyValuePair <string, string>("", Strings.Errors.usernameinvalid));
                }
            }
            else
            {
                Interface.MsgboxErrors.Add(new KeyValuePair <string, string>("", Strings.Errors.notconnected));
            }
        }