private void Register(IOwinContext context, Identification identification)
        {
            var form     = context.Request.ReadFormAsync().Result;
            var identity = _identityDirectory.CreateIdentity();

            try
            {
                if (_identityStore.AddCredentials(identity, form["username"], form["password"]))
                {
                    identification.Identity = identity;
                    identification.Claims   = _identityDirectory.GetClaims(identity);

                    var result = _identityStore.AuthenticateWithCredentials(form["username"], form["password"]);
                    if (result.Status == AuthenticationStatus.Authenticated)
                    {
                        context.Response.Cookies.Append(IdentityCookie, result.Identity);
                        context.Response.Cookies.Append(RememberMeCookie, result.RememberMeToken);
                        SetAuthentication(context, result);
                    }
                }
            }
            catch (Exception e)
            {
                SetOutcome(context, identification, e.Message);
            }
            GoHome(context, identification);
        }
        public void Should_provide_credentials_based_identification()
        {
            const string userName = "******";
            const string password = "******";

            var identity = _identityDirectory.CreateIdentity();
            var success  = _identityStore.AddCredentials(identity, userName, password);

            Assert.IsTrue(success);

            var result = _identityStore.AuthenticateWithCredentials(userName, password);

            Assert.IsNotNull(result);
            Assert.AreEqual(identity, result.Identity);
            Assert.AreEqual(AuthenticationStatus.Authenticated, result.Status);

            result = _identityStore.AuthenticateWithCredentials(userName, "wrong password");

            Assert.IsNotNull(result);
            Assert.AreEqual(identity, result.Identity);
            Assert.AreEqual(AuthenticationStatus.InvalidCredentials, result.Status);

            result = _identityStore.AuthenticateWithCredentials("wrong username", password);

            Assert.IsNotNull(result);
            Assert.AreEqual(AuthenticationStatus.NotFound, result.Status);
        }