コード例 #1
0
            public override void Execute()
            {
                Console.WriteLine("\n-Account Creation-\n");

                Console.WriteLine("Enter username: "******"Enter password: "******"New Account Created...");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        static StubAccountStorage()
        {
            ISecuredPassword securedPasswordCreator = new EncryptionSecuredPassword();

            _Accounts = new List <Account>()
            {
                Account.Existing(
                    new Identity(1),
                    "user1",
                    securedPasswordCreator.Create("password"),
                    new [] { AccessPriviledge.Consumer }),
                Account.Existing(
                    new Identity(2),
                    "Admin",
                    securedPasswordCreator.Create("Administrator123"),
                    new [] { AccessPriviledge.Administrator }),
                Account.Existing(
                    new Identity(3),
                    "SuperUser",
                    securedPasswordCreator.Create("superPassword"),
                    new [] { AccessPriviledge.Consumer, AccessPriviledge.Administrator }),
                Account.Existing(
                    new Identity(4),
                    "consumer",
                    securedPasswordCreator.Create("password"),
                    new [] { AccessPriviledge.Consumer }),
            };
        }
        public override AuthenticationResult Authenticate(string identifier, string password)
        {
            Account found = accountSource.FromUserIdentifier(identifier);

            if (found != null)
            {
                ISecuredPassword passwordChecker = new EncryptionSecuredPassword();

                if (passwordChecker.Verify(password, found.Password))
                {
                    return(new OkResult(found));
                }
                else
                {
                    return(new InvalidCredentialsResult(found.Username));
                }
            }
            else
            {
                return(AuthenticationResult.NotFound);
            }
        }