예제 #1
0
        private void createLoginBtn_Click(object sender, EventArgs e)
        {
            CreateLoginForm createLoginForm = new CreateLoginForm();
            LoginAccount    loginAccount    = null;

            while (true)
            {
                DialogResult loginResult = createLoginForm.ShowDialog(this);
                if (loginResult == DialogResult.OK)
                {
                    NetworkClient client = new NetworkClient(_settings);
                    loginAccount = createLoginForm.getLoginAccount();
                    if (!client.CreateLogin(loginAccount))
                    {
                        MessageBox.Show(this, "Skapande av inloggning misslyckades, användarnamnet finns redan!");
                    }
                    else
                    {
                        login(loginAccount.Username, loginAccount.Password);
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
        }
예제 #2
0
        public bool CreateLogin(LoginAccount loginAccount)
        {
            var values = new Dictionary <string, string>
            {
                { "action", "create_login" },
                { "username", loginAccount.Username },
                { "password", loginAccount.Password },
                { "playername", loginAccount.Playername }
            };

            return(PostReturningBool(new FormUrlEncodedContent(values)));
        }
예제 #3
0
        public bool UpdateLogin(LoginAccount loginAccount, string oldPassword, string oldPlayername)
        {
            var values = new Dictionary <string, string>
            {
                { "action", "update_login" },
                { "username", loginAccount.Username },
                { "newpassword", loginAccount.Password },
                { "newplayername", loginAccount.Playername },
                { "oldpassword", oldPassword },
                { "oldplayername", oldPlayername }
            };

            return(PostReturningBool(new FormUrlEncodedContent(values)));
        }
예제 #4
0
        public static bool TryUpdateLogin(string Username, string newPassword, string newPlayername, string oldPassword, string oldPlayername)
        {
            LoginAccount updateableLoginAccount = new LoginAccount(Username, newPassword, newPlayername);
            //TryUpdate gör inte djup jämförelse (går troligtvis att lägga till stöd för compare i LoginAccount)
            LoginAccount oldLoginAccount;

            if (_loginAccountList.TryGetValue(Username, out oldLoginAccount) && SecurePasswordHasher.Verify(oldPassword, oldLoginAccount.Password) && oldLoginAccount.Playername == oldPlayername)
            {
                return(_loginAccountList.TryUpdate(Username, updateableLoginAccount, oldLoginAccount));
            }
            else
            {
                return(false);
            }
        }
예제 #5
0
 public static bool TryAddLogin(LoginAccount loginAccount)
 {
     return(_loginAccountList.TryAdd(loginAccount.Username, loginAccount));
 }