コード例 #1
0
        public HttpResponseMessage PostLogin(int admin_id, string password)
        {
            bool             Exists = false;
            BankAdmin        admin  = new BankAdmin();
            List <BankAdmin> admins = db.BankAdmins.ToList();

            foreach (var item in admins)
            {
                if (item.admin_id == admin_id)
                {
                    Exists = true;
                    admin  = item;
                    break;
                }
            }

            if (Exists)
            {
                if (admin.admin_password == password)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, "Success"));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, "Wrong Password"));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "Invalid Admin Id"));
            }
        }
コード例 #2
0
        internal Person Login(string email, SecureString password)
        {
            if (!Regex.IsMatch(email, @"\w{3,}@\w{1,}.(com|ie|co.uk|pl)"))
            {
                return(null);
            }

            LoginDetails l = LoginDetails.Login(email);

            if (l == null)
            {
                password.Dispose();
                l = null;
                GC.Collect();
                return(null); // no user
            }
            else if (!VerifyPasswordHash(password, l.Password, l.Salt))
            {
                l = null;
                password.Dispose();
                GC.Collect();
                return(null); // password did not match
            }
            else
            {
                password.Dispose();
                try
                {
                    Person p = null;
                    if (l.Role == Roles.Admin)
                    {
                        BankAdmin temp = Person.SelectById <BankAdmin>(l.UserId);
                        if (temp.Id != l.UserId)
                        {
                            l = null;
                            return(null); // data integrity failed
                        }

                        l = null;
                        p = temp;
                    }
                    else
                    {
                        BankUser temp = Person.SelectById <BankUser>(l.UserId);
                        if (temp.Id != l.UserId)
                        {
                            l = null;
                            GC.Collect();
                            return(null); // data integrity failed
                        }
                        l = null;
                        GC.Collect();

                        p = temp;
                    }
                    LogEntry.SetActor($"{p.FirstName} {p.LastName}", p.Role);

                    return(p);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
コード例 #3
0
ファイル: Register.cs プロジェクト: alanj1998/ConsoleBankApp
        internal override void Render()
        {
            string role, firstName, secondName, address1, address2, address3, phoneNumber, accountType;
            Person p = null;

            Console.WriteLine("Fill out this form to register:\n");

            string[] options  = new string[] { "Admin", "User" };
            Menu     m        = new Menu(options);
            int      resposne = m.RenderMenu();

            switch (resposne)
            {
            case 1:
                role = "Admin";
                break;

            case 2:
            default:
                role = "User";
                break;
            }

            Console.Write("First Name: ");
            firstName = Console.ReadLine();

            Console.Write("Second Name: ");
            secondName = Console.ReadLine();

            Console.Write("Address 1: ");
            address1 = Console.ReadLine();

            Console.Write("Address 2: ");
            address2 = Console.ReadLine();

            Console.Write("Address 3: ");
            address3 = Console.ReadLine();

            Console.Write("Phone Number: ");
            phoneNumber = Console.ReadLine();

            if (role == "Admin")
            {
                BankAdmin admin = new BankAdmin()
                {
                    FirstName   = firstName,
                    LastName    = secondName,
                    Address1    = address1,
                    Address2    = address2,
                    Address3    = address3,
                    Role        = (Roles)Enum.Parse(typeof(Roles), role),
                    PhoneNumber = phoneNumber
                };

                Console.Write("Enter your branch location: ");
                admin.BranchLocation = Console.ReadLine();

                try
                {
                    p = BankAdmin.InsertNewObject <BankAdmin>(admin);
                    Helpers.FreeAndNil(ref admin);
                }
                catch (System.Exception err)
                {
                    Console.WriteLine(err.Message);
                    throw err;
                }
            }
            else
            {
                Console.Write("Enter account type: ");
                accountType = Console.ReadLine();

                BankUser user = new BankUser()
                {
                    AccountType = accountType,
                    Address1    = address1,
                    Address2    = address2,
                    Address3    = address3,
                    FirstName   = firstName,
                    LastName    = secondName,
                    PhoneNumber = phoneNumber,
                    Role        = (Roles)Enum.Parse(typeof(Roles), role)
                };

                try
                {
                    p = BankUser.InsertNewObject <BankUser>(user);
                    Helpers.FreeAndNil(ref user);
                }
                catch (System.Exception err)
                {
                    Console.WriteLine(err.Message);
                }
            }

            bool result = this.SetupLogin(p);

            if (result)
            {
                this._router.Navigate(Routes.Dashboard, p);
            }
            else
            {
                Console.WriteLine("There has been an error setting up your credentials...");
                this._router.Navigate(Routes.Splash);
            }
        }