コード例 #1
0
        /// <summary>
        /// login
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void LoginClickEven(object sender, EventArgs e)
        {
            txtName = FindViewById <EditText>(Resource.Id.txt_name);
            txtPwd  = FindViewById <EditText>(Resource.Id.txt_pwd);

            string domain = this.GetString(Resource.String.domain);
            string url    = domain + "user/login";
            IDictionary <string, string> routeParames = new Dictionary <string, string>();

            routeParames.Add("userName", DESHelper.DESEncrypt(this.txtName.Text));
            routeParames.Add("userPassword", DESHelper.DESEncrypt(HMACMD5Encrypt.GetEncryptResult(this.txtPwd.Text)));

            var test = HMACMD5Encrypt.GetEncryptResult(this.txtPwd.Text);

            var result = await EasyWebRequest.SendPostRequestBasedOnHttpClient(url, routeParames);

            //var result = await EasyWebRequest.SendPostHttpRequestBaseOnHttpWebRequest(url, routeParames);
            var data = (JsonObject)result;

            if (data["Code"] == "0000")
            {
                var share  = GetSharedPreferences("finance", FileCreationMode.Private);
                var editor = share.Edit();
                editor.PutString("name", txtName.Text).Commit();

                Intent intent = new Intent(this, typeof(MainActivity));
                StartActivity(intent);
                Finish();
            }
            else
            {
                Toast.MakeText(this, "Login fail,please check your name and password", ToastLength.Long).Show();
            }
        }
コード例 #2
0
        /// <summary>
        /// user registrate button click even
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void RegistrateEven(object sender, EventArgs e)
        {
            txtName     = FindViewById <EditText>(Resource.Id.et_name);
            txtPwd      = FindViewById <EditText>(Resource.Id.et_pwd);
            txtEmail    = FindViewById <EditText>(Resource.Id.et_email);
            _userGender = rg.CheckedRadioButtonId == Resource.Id.rbtn_man ? "male" : "female";

            string domain = this.GetString(Resource.String.domain);
            string url    = domain + "user/register";
            IDictionary <string, string> routeParames = new Dictionary <string, string>();

            routeParames.Add("userName", DESHelper.DESEncrypt(this.txtName.Text));
            routeParames.Add("userPassword", DESHelper.DESEncrypt(HMACMD5Encrypt.GetEncryptResult(this.txtPwd.Text)));
            routeParames.Add("gender", DESHelper.DESEncrypt(this._userGender));
            routeParames.Add("email", DESHelper.DESEncrypt(this.txtEmail.Text));

            var result = await EasyWebRequest.SendPostRequestBasedOnHttpClient(url, routeParames);

            var data = (JsonObject)result;

            if (data["Code"] == "0000")
            {
                Intent intent = new Intent(this, typeof(MainActivity));
                StartActivity(intent);
                Finish();
            }
            else
            {
                Toast.MakeText(this, "Register fail", ToastLength.Long).Show();
            }
        }
コード例 #3
0
        public void login_should_be_faile_and_return_false()
        {
            _fakeObject.Setup(x => x.LogIn(It.IsAny <string>(), It.IsAny <string>())).Returns(false);

            var actual = _fakeObject.Object.LogIn("test", HMACMD5Encrypt.GetEncryptResult("123"));

            Assert.Equal(false, actual);
        }
コード例 #4
0
        public void login_should_success_and_return_uid()
        {
            _fakeObject.Setup(x => x.LogInAndReturnUID(It.IsAny <string>(), It.IsAny <string>())).Returns(System.Guid.Parse("d2903097-cfd1-46e5-b197-e8c51f1d20e2"));

            var actual = _fakeObject.Object.LogInAndReturnUID("admin", HMACMD5Encrypt.GetEncryptResult("123"));

            Assert.Equal(System.Guid.Parse("d2903097-cfd1-46e5-b197-e8c51f1d20e2"), actual);
        }
コード例 #5
0
        public void HMACMD5Encrypt_Should_Be_Right()
        {
            string data           = "123";
            string expectedResult = "6DE767819DC54477DFC4C670F74FFFA7";

            string actualResult = HMACMD5Encrypt.GetEncryptResult(data);

            Assert.Equal(expectedResult, actualResult);
        }
コード例 #6
0
        /// <summary>
        /// login
        /// </summary>
        /// <param name="name">the name user input</param>
        /// <param name="pwd">the password user input</param>
        /// <returns></returns>
        private dynamic Login(string name, string pwd)
        {
            Guid adminID = _adminLogic.LogInAndReturnUID(name, HMACMD5Encrypt.GetEncryptResult(pwd));

            if (adminID != new Guid())
            {
                Session["name"] = name;

                return(this.LoginAndRedirect(adminID, fallbackRedirectUrl: "/main"));
            }
            else
            {
                return(View["index"]);
            }
        }