SHOW:
|
|
- or go back to the newest paste.
1 | /*Default.aspx*\ | |
2 | <!DOCTYPE html> | |
3 | ||
4 | <html xmlns="http://www.w3.org/1999/xhtml"> | |
5 | <head runat="server"> | |
6 | <style> | |
7 | form { | |
8 | width: 300px; | |
9 | ||
10 | } | |
11 | ||
12 | div { | |
13 | width: 300px; | |
14 | background-color: lightblue; | |
15 | } | |
16 | ||
17 | h3 { | |
18 | text-align:center; | |
19 | } | |
20 | ||
21 | label { | |
22 | width: 100px; | |
23 | margin: 10px 10px 10px 10px; | |
24 | float: left; | |
25 | display:block; | |
26 | } | |
27 | ||
28 | input{ | |
29 | width: 50px; | |
30 | margin: 10px 10px 10px 10px; | |
31 | } | |
32 | ||
33 | .Textbox{ | |
34 | width: 130px; | |
35 | margin: 10px 10px 10px 10px; | |
36 | } | |
37 | ||
38 | span{ | |
39 | ||
40 | } | |
41 | ||
42 | .Errore { | |
43 | color: red; | |
44 | text-decoration: underline; | |
45 | } | |
46 | ||
47 | ||
48 | </style> | |
49 | <title></title> | |
50 | </head> | |
51 | <body> | |
52 | <form id="form1" runat="server"> | |
53 | <div> | |
54 | <h3>FORM AUTHENTICATION</h3> | |
55 | <asp:Label ID="Label1" runat="server" Text="Benvenuto"></asp:Label><br /> | |
56 | <asp:Button ID="Return" runat="server" OnClick="Return_Click" Text="Log Out" /> | |
57 | </div> | |
58 | </form> | |
59 | </body> | |
60 | </html> | |
61 | /*Default.aspx.cs*\ | |
62 | using System; | |
63 | using System.Collections.Generic; | |
64 | using System.Linq; | |
65 | using System.Web; | |
66 | using System.Web.UI; | |
67 | using System.Web.UI.WebControls; | |
68 | using System.Web.Security; | |
69 | using System.Data.Sql; //Usa questa se usate Sql Server | |
70 | using System.Data.SqlClient; | |
71 | using System.Data; | |
72 | ||
73 | ||
74 | namespace LogIN | |
75 | { | |
76 | public partial class Default : System.Web.UI.Page | |
77 | { | |
78 | protected void Page_Load(object sender, EventArgs e) | |
79 | { | |
80 | Label1.Text = "Benvenuto "+ Context.User.Identity.Name; | |
81 | } | |
82 | ||
83 | protected void Return_Click(object sender, EventArgs e) | |
84 | { | |
85 | FormsAuthentication.SignOut(); | |
86 | Response.Redirect("LogIN.aspx"); | |
87 | } | |
88 | } | |
89 | } | |
90 | /*LogIN.aspx*\ | |
91 | <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LogIN.aspx.cs" Inherits="LogIN.LogIN" %> | |
92 | ||
93 | <!DOCTYPE html> | |
94 | ||
95 | <html xmlns="http://www.w3.org/1999/xhtml"> | |
96 | <head runat="server"> | |
97 | <style> | |
98 | form { | |
99 | width: 300px; | |
100 | ||
101 | } | |
102 | ||
103 | div { | |
104 | width: 300px; | |
105 | background-color: lightblue; | |
106 | } | |
107 | ||
108 | h3 { | |
109 | text-align:center; | |
110 | } | |
111 | ||
112 | label { | |
113 | width: 100px; | |
114 | margin: 10px 10px 10px 10px; | |
115 | float: left; | |
116 | display:block; | |
117 | } | |
118 | ||
119 | input{ | |
120 | width: 50px; | |
121 | margin: 10px 10px 10px 10px; | |
122 | } | |
123 | ||
124 | .Textbox{ | |
125 | width: 130px; | |
126 | margin: 10px 10px 10px 10px; | |
127 | } | |
128 | ||
129 | span{ | |
130 | color: red; | |
131 | } | |
132 | ||
133 | .Errore { | |
134 | color: red; | |
135 | text-decoration: underline; | |
136 | } | |
137 | ||
138 | </style> | |
139 | ||
140 | <!--<script type="text/javascript"> | |
141 | ||
142 | function Controll() { | |
143 | if (document.getElementById("Usermail").innerText == "" || document.getElementById("Userpass").innerText == "") { | |
144 | if (document.getElementById("Usermail").innerText == "") { | |
145 | document.getElementById("ctrlfield1").innerText = "Cannot be blank"; | |
146 | } else { | |
147 | document.getElementById("ctrlfield1").innerText = ""; | |
148 | } | |
149 | if (document.getElementById("Userpass").innerText == "") { | |
150 | document.getElementById("ctrlfield2").innerText = "Cannot be blank"; | |
151 | } else { | |
152 | document.getElementById("ctrlfield2").innerText = ""; | |
153 | } | |
154 | return false; | |
155 | } | |
156 | } | |
157 | ||
158 | </script>--> | |
159 | <title>Pagina Di Log IN</title> | |
160 | </head> | |
161 | <body> | |
162 | <form id="form1" runat="server"> | |
163 | <div> | |
164 | <h3> Pagina di Log IN </h3> | |
165 | <label>User</label> | |
166 | <asp:TextBox ID="Username" class="Textbox" runat="server"></asp:TextBox> | |
167 | <asp:RequiredFieldValidator ID="RFV1" ErrorMessage="*" Display="Dynamic" runat="server" ControlToValidate="Username" /> | |
168 | <br /> | |
169 | <label>Pass</label> | |
170 | <asp:TextBox ID="Password" class="Textbox" TextMode="Password" runat="server"></asp:TextBox> | |
171 | <asp:RequiredFieldValidator ID="RFV2" ControlToValidate="Password" Display="Dynamic" runat="server" ErrorMessage="*" /> | |
172 | <br /> | |
173 | <label>Remember me?</label> | |
174 | <asp:CheckBox ID="Persist" runat="server" /><br /> | |
175 | <asp:Button ID="Submit" OnClick="Submit_Click" runat="server" Text="Invia" /> | |
176 | <asp:Button ID="Reset" OnClick="Reset_Click" runat="server" Text="Reset" /><br /> | |
177 | <asp:Label ID="ErrorLogIN" class="Errore" runat="server"></asp:Label> | |
178 | </div> | |
179 | </form> | |
180 | </body> | |
181 | </html> | |
182 | /*LogIN.aspx.cs*\ | |
183 | using System; | |
184 | using System.Collections.Generic; | |
185 | using System.Linq; | |
186 | using System.Web; | |
187 | using System.Web.UI; | |
188 | using System.Web.UI.WebControls; | |
189 | using System.Web.Security; | |
190 | using System.Data.Sql; //Usa questa se usate Sql Server | |
191 | using System.Data.SqlClient; | |
192 | using System.Data; | |
193 | using System.Data.OleDb; // Usa questa per Access | |
194 | ||
195 | ||
196 | namespace LogIN | |
197 | { | |
198 | public partial class LogIN : System.Web.UI.Page | |
199 | { | |
200 | protected void Page_Load(object sender, EventArgs e) | |
201 | { | |
202 | ||
203 | } | |
204 | ||
205 | protected void Submit_Click(object sender, EventArgs e) | |
206 | { | |
207 | SqlConnection dbconn = new SqlConnection(); | |
208 | SqlCommand dbcomm; | |
209 | //OleDbConnection dbconn = new OleDbConnection(); | |
210 | 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; | |
211 | string output = "", strsql = "SELECT Pass FROM [dbo].[Users] WHERE Users = '"+Username.Text+"'"; //strsql = La query da fare; | |
212 | ||
213 | try { | |
214 | dbconn.Open(); | |
215 | dbcomm = new SqlCommand(strsql, dbconn); | |
216 | output = dbcomm.ExecuteScalar().ToString(); | |
217 | } | |
218 | catch(SqlException ex) { | |
219 | Response.Write(ex); | |
220 | } | |
221 | ||
222 | if ((Username.Text != "") && (Password.Text == output)) { | |
223 | FormsAuthentication.RedirectFromLoginPage(Username.Text, Persist.Checked); | |
224 | } | |
225 | else { | |
226 | ErrorLogIN.Text = "Invalid Fields"; | |
227 | } | |
228 | dbconn.Close(); | |
229 | } | |
230 | ||
231 | protected void Reset_Click(object sender, EventArgs e) | |
232 | { | |
233 | ||
234 | Username.Text = ""; | |
235 | Password.Text = ""; | |
236 | } | |
237 | } | |
238 | } | |
239 | /*Web.config*\ | |
240 | <?xml version="1.0" encoding="utf-8"?> | |
241 | ||
242 | <!-- | |
243 | For more information on how to configure your ASP.NET application, please visit | |
244 | https://go.microsoft.com/fwlink/?LinkId=169433 | |
245 | --> | |
246 | <configuration> | |
247 | <system.web> | |
248 | <authentication mode ="Forms"> | |
249 | <forms loginUrl="LogIN.aspx" name=".ASPXLOGINFORM" /> | |
250 | </authentication> | |
251 | <authorization> | |
252 | <deny users="?" /> | |
253 | </authorization> | |
254 | <compilation debug="true" targetFramework="4.7.2"/> | |
255 | <httpRuntime targetFramework="4.7.2"/> | |
256 | </system.web> | |
257 | <system.codedom> | |
258 | <compilers> | |
259 | <compiler language="c#;cs;csharp" extension=".cs" | |
260 | type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" | |
261 | warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/> | |
262 | <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" | |
263 | type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" | |
264 | warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/> | |
265 | </compilers> | |
266 | </system.codedom> | |
267 | <appSettings> | |
268 | <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" /> | |
269 | </appSettings> | |
270 | </configuration> |