コード例 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.login_page);
            Android.Widget.Button buttonLogIn = FindViewById <Android.Widget.Button>(Resource.Id.buttonLogIn);
            var emailInput    = FindViewById <TextView>(Resource.Id.textInsertEmail);
            var passwordInput = FindViewById <TextView>(Resource.Id.textInsertPassword);

            buttonLogIn.Click += (e, o) =>
            {
                string password = PCLCrypto.GenerateHash(passwordInput.Text);
                List <SqlParameter> sqlParameters = new List <SqlParameter>
                {
                    new SqlParameter("Email", emailInput.Text),
                    new SqlParameter("Password", password)
                };

                DataTable loginResults = DatabaseConnection.ExecSp("ValidateLogin", sqlParameters);
                if (loginResults.Rows.Count == 1)
                {
                    DataRow storedResults = loginResults.Rows[0];
                    User    currentUser   = User.Instance;
                    currentUser.password         = passwordInput.Text;
                    currentUser.email            = storedResults["Email"].ToString();
                    currentUser.firstName        = storedResults["FirstName"].ToString();
                    currentUser.lastName         = storedResults["LastName"].ToString();
                    currentUser.phoneNumber      = storedResults["PhoneNumber"].ToString();
                    currentUser.birthDate        = Convert.ToDateTime(storedResults["BirthDate"].ToString());
                    currentUser.numberOfAccounts = Convert.ToInt32(storedResults["NumberOfAccounts"]);
                    currentUser.id = Convert.ToInt32(storedResults["Id"]);
                    for (int i = 0; i < currentUser.numberOfAccounts; i++)
                    {
                        int j = i + 1;
                        currentUser.accountList[i].iban     = storedResults["Account" + j.ToString() + "_Iban"].ToString();
                        currentUser.accountList[i].balance  = (float)Convert.ToDouble(storedResults["Account" + j.ToString() + "_Balance"]);
                        currentUser.accountList[i].currency = storedResults["Account" + j.ToString() + "_Currency"].ToString();
                    }
                    Toast.MakeText(ApplicationContext, "Welcome!", ToastLength.Long).Show();
                    Intent nextActivity = new Intent(this, typeof(MainPage));
                    StartActivity(nextActivity);
                }
                else
                {
                    Toast.MakeText(ApplicationContext, "Wrong email/password", ToastLength.Long).Show();
                }
            };
        }
コード例 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.register_page);
            Android.Widget.Button buttonSignUp = FindViewById <Android.Widget.Button>(Resource.Id.buttonSignUp);
            var    emailInput    = FindViewById <TextView>(Resource.Id.textInsertEmail);
            var    passwordInput = FindViewById <TextView>(Resource.Id.textInsertPassword);
            var    firstName     = FindViewById <TextView>(Resource.Id.textInsertFirstName);
            var    lastName      = FindViewById <TextView>(Resource.Id.textInsertLastName);
            var    phoneNumber   = FindViewById <TextView>(Resource.Id.textInsertPhoneNumber);
            var    birthDate     = FindViewById <TextView>(Resource.Id.textInsertBirthDate);
            int    ok;
            string password = "";

            buttonSignUp.Click += (e, o) =>
            {
                ok = 1;
                if (passwordInput.Text.Length <= 3)
                {
                    Toast.MakeText(ApplicationContext, "Password must be at least 4 characters long", ToastLength.Long).Show();
                    ok = 0;
                }
                else
                {
                    password = PCLCrypto.GenerateHash(passwordInput.Text);
                }
                if (emailInput.Text.Length <= 6 || !emailInput.Text.Contains('@'))
                {
                    Toast.MakeText(ApplicationContext, "Invalid email", ToastLength.Long).Show();
                    ok = 0;
                }
                if (firstName.Text.Length <= 2 || lastName.Text.Length <= 2)
                {
                    Toast.MakeText(ApplicationContext, "Invalid name", ToastLength.Long).Show();
                    ok = 0;
                }
                if (phoneNumber.Text.Length <= 7)
                {
                    Toast.MakeText(ApplicationContext, "Invalid phone number", ToastLength.Long).Show();
                    ok = 0;
                }
                if (ok == 1)
                {
                    List <SqlParameter> sqlParameters = new List <SqlParameter>
                    {
                        new SqlParameter("Email", emailInput.Text)
                    };
                    DataTable validateEmailResults = DatabaseConnection.ExecSp("ValidateEmail", sqlParameters);
                    if (validateEmailResults.Rows.Count > 0)
                    {
                        Toast.MakeText(ApplicationContext, "Email already used", ToastLength.Long).Show();
                    }
                    else
                    {
                        List <SqlParameter> sqlParameters2 = new List <SqlParameter>
                        {
                            new SqlParameter("Email", emailInput.Text),
                            new SqlParameter("Password", password),
                            new SqlParameter("FirstName", firstName.Text),
                            new SqlParameter("LastName", lastName.Text),
                            new SqlParameter("PhoneNumber", phoneNumber.Text),
                            new SqlParameter("BirthDate", birthDate.Text)
                        };

                        DatabaseConnection.ExecSp("CreateUser", sqlParameters2);

                        Toast.MakeText(ApplicationContext, "Account created!", ToastLength.Long).Show();
                        Finish();
                    }
                }
            };
        }