public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { return(Task.Factory.StartNew(() => { var email = context.UserName; var password = context.Password; daoUtente daoUtente = new daoUtente(); Utente U = new Utente(); U.Email = email; U.Password = password; Utente oUser = daoUtente.Login(U); if (oUser != null) { var claims = new List <Claim>() { new Claim(ClaimTypes.Sid, Convert.ToString(oUser.ID)), new Claim(ClaimTypes.Name, oUser.Nome), new Claim(ClaimTypes.Email, oUser.Email) }; ClaimsIdentity oAuthIdentity = new ClaimsIdentity(claims, Startup.OAuthOptions.AuthenticationType); var properties = CreateProperties(oUser); var ticket = new AuthenticationTicket(oAuthIdentity, properties); context.Validated(ticket); } else { context.SetError("invalid_grant", "The user name or password is incorrect"); } })); }
protected void btnLogin_Click(object sender, EventArgs e) { if (txbUsername.Text != "" & txbPassword.Text != "") { Utente oUtente = new Utente(); oUtente.Username = txbUsername.Text; oUtente.Password = txbPassword.Text; daoUtente daoU = new daoUtente(); oUtente = daoU.getLogin(oUtente); if (oUtente.ID > 0) { Session.Add("utente", oUtente); Response.Redirect("default.aspx"); } else { txbUsername.Text = ""; txbPassword.Text = ""; pnl_Error.Visible = true; } } pnl_Error.Visible = true; }