484171-001
Would you like to react to this message? Create an account in a few clicks or log in to continue.
484171-001

484171-001
 
HomeHome  PortalPortal  Latest imagesLatest images  SearchSearch  RegisterRegister  Log in  

 

 Logging In Using ASP - Access2000

Go down 
AuthorMessage
Admin
Admin



Posts : 304
Join date : 2011-09-04

Logging In Using ASP - Access2000 Empty
PostSubject: Logging In Using ASP - Access2000   Logging In Using ASP - Access2000 Icon_minitimeMon Sep 12, 2011 3:32 pm

After receiving a few queries about how precisely exactly to store passwords usingACCESS as well as ASP, and then have tried them as "logins", I imagined, well, why not write in a very separate article, instead of attachingmultiple ASP files which have been full of confusing comments andvariables just to be decipherable by my personal brain? I'm assuming you installed, and are running PWS (Personal WebServer) on the machine, if you usually are not already working on aserver which supports ASP. First in all, create a database, as an illustration, customers. Define atable because of the fields you require (include mail andpassword). After the database have been created, you need to make a DNS inorder to get this database through your own ASP pages. If you have got never created it, this is why you do it: Visit the Control Panel (My Laptop -> Control Panel), and clickon the icon that ought to be saying "ODBC Data Places (32bit)". Inthe resulting screen, select the "System DSN" case. Then click onthe "Add... " button. From the given report on Database drivers, select "Microsoft Gain access to Driver (*. mdb)" and click the "Finish"button. You reach a place where you will need to enter the "DataSource Name". Type in it, anything, for circumstance, "customers". Thenclick the "Select... " button. This lets you want the Accessdatabase you manufactured. Press Ok, press Fine, and press Ok. Your current DSNis created. In the 1st part, I'll write pertaining to storing the passwords. Ahead of this, let's make an include file to make and initializethe session variables that we will need (we can usecookies, but some clever folks disable biscuits on theirbrowsers). File brand: sessions. inc< %if session("email")="" and then session("email")="notlogged" session("pass")=""end if%> This file you can include in every page as<! --#include file="sessions. inc"--> to help you use them whenever you require them. Now accepting account and password. For this you might need a normal HTML shape. You can have "n" numberof fields inside of a form, but here, each of our primary concern is, gettingthe electronic mail as login, and that accompanying password. Here's the shape: Please enter your points: < form name="login_info" method="post" action="storelog. asp"onsubmit="return validate(this); "> Type in Email: < input type="edit" name="email" size="15"> Type in Password: < input type="password" name="pass" size="15"> < insight type="submit" value="Submit"> < /form> We validate the shape before it proceeds on the "action" file sothat there is always very little server-side digesting. A simplevalidation: Note: Put this Javascript above the < body> marking. < script language="JavaScript"> function validate()document.login_info.email.value==null) alert("Sorry, you cannot register without an emailaddress."); res=false; allok=false; document.login_info.email.focus(); // Checking that the password is right. if(allok==true) // I'm using allok here because if allok is false, no usechecking for the next field. if(document.login_info.pass.value.length<6 return res; < /script> So now if your user clicks on "Submit", he/she moves to"storelog. asp" In around, you can have a file to verify theform fields and required user an option to modify them beforefinally saving. A number of things. In order to utilize a database through ASP, you may need tohave a DNS devised for that database on that server. STORELOG. ASP should somewhat resemble this: < %dim sEmail, sPass, noErrornoError="y"sEmail=request. form("email")sPass=request. form("pass")' This lines setup a link with the DNS we createdaboveDim toDatabase 'To get connected to the DNSDim toRecordset 'To connect with the individual tablesSet toDatabase = Server. CreateObject("ADODB. Connection")toDatabase. Wide open "customers"Set toRecordset = Server. CreateObject("ADODB. Recordset")toRecordset. Wide open "logins", toDatabase, 2' 2 = Frees the recordset in "Write Mode"' Allow us to say "logins" is quite a few table you created inside database. toRecordset. AddNewtoRecordset("email")=sEmailtoRecordset("password")=sPasson miscalculation resume nexttoRecordset. Updateif err. number< > 0 then' take a step if some error takes place. ' one error may be that the email currently exists in thedatabase. noError="n"end iftoRecordset. CloseSet toRecordset = NothingtoDatabase. CloseSet toDatabase = Nothingif noError="y" then' If your info was saved easily. session("email")=sEmail session("pass")=sPassend if' Here you'll be able to display some message that this record has beensaved. %> This saves the login information of an new customer. Now, how dowe use it down the road? First, the login shape, that could be onany webpage. Remember you can work with somewhat same validation Javascript heretoo, consequently I'm not repeating that, but just mentioning them. Please login by joining your email and username and password. < form name="login" method="post" action="login. asp"onsubmit="return validate(this); "> Type in Email: < input type="edit" name="email" size="15"> Type in Password: < input type="password" name="pass" size="15"> < insight type="Submit" value="Submit"> < /form> LOGON. ASPAt the top belonging to the page, along with some other ASP commands, includethis way too: < % response. buffer=true %> This is required if you need to send the user for some page afterhe/she has effectively logged in. < %dim sEmail, sPass, noErrornoError="y"sEmail=request. form("email")sPass=request. form("pass")' This lines setup a link with the DNS we createdaboveDim toDatabase 'To get connected to the DNSDim toRecordset 'To connect with the individual tablesSet toDatabase = Server. CreateObject("ADODB. Connection")toDatabase. Wide open "customers"fndSQL="select * from logins at which email='" & sEmail & "' andpassword='" & sPass & "'"Set toRecordset=toDatabase. execute(fndSQL)if toRecordset. eof and then response. write "Your details are certainly not in the database, pleasetry yet again, or register yourself. "else session("email")=toRecordset("email") session("pass")=toRecordset("password")end iftoRecordset. CloseSet toRecordset = NothingtoDatabase. CloseSet toDatabase = Nothingresponse. refocus "To some URL"%> > Via now onwards, whenever you wish to perform some action thatshould only be performed if your user is logged within, just check thevalue is without a doubt session("email"), like: < %if session("email")< > "notlogged" then' do things to the logged in customerelse' tell the buyer that he she just isn't logged in. end if%> Hope this assists. If you need additionally queries, or in future youneed a few other ASP work, you are welcome to to me atamrit@bytesworth. com.
Back to top Go down
https://484171-001.forumotion.com
 
Logging In Using ASP - Access2000
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
484171-001 :: Your first category :: Your first forum-
Jump to: