Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Default.aspx*\
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <style>
- form {
- width: 300px;
- }
- div {
- width: 300px;
- background-color: lightblue;
- }
- h3 {
- text-align:center;
- }
- label {
- width: 100px;
- margin: 10px 10px 10px 10px;
- float: left;
- display:block;
- }
- input{
- width: 50px;
- margin: 10px 10px 10px 10px;
- }
- .Textbox{
- width: 130px;
- margin: 10px 10px 10px 10px;
- }
- span{
- }
- .Errore {
- color: red;
- text-decoration: underline;
- }
- </style>
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <h3>FORM AUTHENTICATION</h3>
- <asp:Label ID="Label1" runat="server" Text="Benvenuto"></asp:Label><br />
- <asp:Button ID="Return" runat="server" OnClick="Return_Click" Text="Log Out" />
- </div>
- </form>
- </body>
- </html>
- /*Default.aspx.cs*\
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.Security;
- using System.Data.Sql; //Usa questa se usate Sql Server
- using System.Data.SqlClient;
- using System.Data;
- namespace LogIN
- {
- public partial class Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- Label1.Text = "Benvenuto "+ Context.User.Identity.Name;
- }
- protected void Return_Click(object sender, EventArgs e)
- {
- FormsAuthentication.SignOut();
- Response.Redirect("LogIN.aspx");
- }
- }
- }
- /*LogIN.aspx*\
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LogIN.aspx.cs" Inherits="LogIN.LogIN" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <style>
- form {
- width: 300px;
- }
- div {
- width: 300px;
- background-color: lightblue;
- }
- h3 {
- text-align:center;
- }
- label {
- width: 100px;
- margin: 10px 10px 10px 10px;
- float: left;
- display:block;
- }
- input{
- width: 50px;
- margin: 10px 10px 10px 10px;
- }
- .Textbox{
- width: 130px;
- margin: 10px 10px 10px 10px;
- }
- span{
- color: red;
- }
- .Errore {
- color: red;
- text-decoration: underline;
- }
- </style>
- <!--<script type="text/javascript">
- function Controll() {
- if (document.getElementById("Usermail").innerText == "" || document.getElementById("Userpass").innerText == "") {
- if (document.getElementById("Usermail").innerText == "") {
- document.getElementById("ctrlfield1").innerText = "Cannot be blank";
- } else {
- document.getElementById("ctrlfield1").innerText = "";
- }
- if (document.getElementById("Userpass").innerText == "") {
- document.getElementById("ctrlfield2").innerText = "Cannot be blank";
- } else {
- document.getElementById("ctrlfield2").innerText = "";
- }
- return false;
- }
- }
- </script>-->
- <title>Pagina Di Log IN</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <h3> Pagina di Log IN </h3>
- <label>User</label>
- <asp:TextBox ID="Username" class="Textbox" runat="server"></asp:TextBox>
- <asp:RequiredFieldValidator ID="RFV1" ErrorMessage="*" Display="Dynamic" runat="server" ControlToValidate="Username" />
- <br />
- <label>Pass</label>
- <asp:TextBox ID="Password" class="Textbox" TextMode="Password" runat="server"></asp:TextBox>
- <asp:RequiredFieldValidator ID="RFV2" ControlToValidate="Password" Display="Dynamic" runat="server" ErrorMessage="*" />
- <br />
- <label>Remember me?</label>
- <asp:CheckBox ID="Persist" runat="server" /><br />
- <asp:Button ID="Submit" OnClick="Submit_Click" runat="server" Text="Invia" />
- <asp:Button ID="Reset" OnClick="Reset_Click" runat="server" Text="Reset" /><br />
- <asp:Label ID="ErrorLogIN" class="Errore" runat="server"></asp:Label>
- </div>
- </form>
- </body>
- </html>
- /*LogIN.aspx.cs*\
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.Security;
- using System.Data.Sql; //Usa questa se usate Sql Server
- using System.Data.SqlClient;
- using System.Data;
- using System.Data.OleDb; // Usa questa per Access
- namespace LogIN
- {
- public partial class LogIN : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void Submit_Click(object sender, EventArgs e)
- {
- SqlConnection dbconn = new SqlConnection();
- SqlCommand dbcomm;
- //OleDbConnection dbconn = new OleDbConnection();
- dbconn.ConnectionString = @"Data Source = DESKTOP-U5E7EUI\SQLEXPRESS; Initial Catalog = DBLogIN; Integrated Security = SSPI;"; //Data Source = Il proprio Server; Initial Catalog = Il Database; Integrated Security = SSPI;
- string output = "", strsql = "SELECT Pass FROM [dbo].[Users] WHERE Users = '"+Username.Text+"'"; //strsql = La query da fare;
- try {
- dbconn.Open();
- dbcomm = new SqlCommand(strsql, dbconn);
- output = dbcomm.ExecuteScalar().ToString();
- }
- catch(SqlException ex) {
- Response.Write(ex);
- }
- if ((Username.Text != "") && (Password.Text == output)) {
- FormsAuthentication.RedirectFromLoginPage(Username.Text, Persist.Checked);
- }
- else {
- ErrorLogIN.Text = "Invalid Fields";
- }
- dbconn.Close();
- }
- protected void Reset_Click(object sender, EventArgs e)
- {
- Username.Text = "";
- Password.Text = "";
- }
- }
- }
- /*Web.config*\
- <?xml version="1.0" encoding="utf-8"?>
- <!--
- For more information on how to configure your ASP.NET application, please visit
- https://go.microsoft.com/fwlink/?LinkId=169433
- -->
- <configuration>
- <system.web>
- <authentication mode ="Forms">
- <forms loginUrl="LogIN.aspx" name=".ASPXLOGINFORM" />
- </authentication>
- <authorization>
- <deny users="?" />
- </authorization>
- <compilation debug="true" targetFramework="4.7.2"/>
- <httpRuntime targetFramework="4.7.2"/>
- </system.web>
- <system.codedom>
- <compilers>
- <compiler language="c#;cs;csharp" extension=".cs"
- type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
- warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
- <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
- type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
- warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
- </compilers>
- </system.codedom>
- <appSettings>
- <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
- </appSettings>
- </configuration>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement