473,840 Members | 1,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple username checking

nix
Hi

I want to create a simple user validation script without using a database.

Let's say I have a text file in my asp folder with a list of valid
usernames. How can i do something like the following using ASP?
// IN: sUsername

try
AUsernameList:= TStringlist.cre ate;
try
AUsernameList.l oadfromfile('us ernames.txt');
bValidUser:=Ind exOf(sUsername) >=0;
except
// OUTPUT AN ERROR TO THE USER
end;
finally
AUsernameList.f ree;
end;

// OUT: bValidUser
Thanks

nix
Jul 22 '05 #1
2 1307
nix wrote:
Let's say I have a text file in my asp folder with a list of valid
usernames. How can i do something like the following using ASP?

try
AUsernameList:= TStringlist.cre ate;
try
AUsernameList.l oadfromfile('us ernames.txt');
bValidUser:=Ind exOf(sUsername) >=0;
except
// OUTPUT AN ERROR TO THE USER
end;
finally
AUsernameList.f ree;
end;


Supposing usernames.txt has a different username on each line, this general
approach would do...

<%@ Language=JScrip t %><%
var UserID = Request.Form("U serID").Item,
filePathName = "c:\\your\\path \\usernames.txt ",
fso = Server.CreateOb ject("Scripting .FileSystemObje ct"),
file = fso.OpenTextFil e(filePathName) .ReadAll(),
re = new RegExp("\r\n"+U serID+"\r\n", "i")

if (re.test(file)) {
// success code
} else {
// failure code
}
%>

Note: I used a regular expression to avoid iteration. String.indexOf( ) could
be used as well. Either should test for being a whole match -- a simple
indexOf("n") would match "nix" if you are not careful. That's why I
bookended the matching string with newline characters. This, of course,
requires a newline character before the first entry and another after the
last.

Of course, your text file might contain more than just user ids. Suppose
each line contained UserID, last name, and first name, tab-delimited. Then
you would want an iterative approach. Here's one:

var UserID = Request.Form("U serID").Item,
filePathName = "c:\\your\\path \\usernames.txt ",
fso = Server.CreateOb ject("Scripting .FileSystemObje ct"),
file = fso.OpenTextFil e(filePathName) .ReadAll(),
re = new RegExp("\r\n"+U serID+"\t", "i"),
users = file.split("\r\ n")

if (re.test(file)) {
re = new RegExp(UserID+" \t", "i")
for (var i=0; i<users.length ; i++)
if (re.test(users[i])) {
var UserID = users[i].split("\t")[0],
LastName = users[i].split("\t")[1],
FirstName = users[i].split("\t")[2]
// remainder of success code
}
} else {
// failure code
}

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 22 '05 #2
nix
Excellent,

Dave
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
4760
by: Samantha Smit | last post by:
Hi, I am trying to create a simple asp page that has one command button that updates a database. The URL of the page is like this: http://MyServer.com/Update.asp?UserName=Tom My asp code is like this: %@ Language=VBScript %> <!--#include file="includes/openconnection.asp"-->
5
5475
by: nikou_70 | last post by:
I have a problem with ("auth_user") in asp,I try to use windows username and password in asp page for limitation user access to pages, but this server variable returns empty string, can you help me ,I appreciate it.
1
4760
by: sankviju | last post by:
Here i created a javascript+php code by which u can create a check available link that u will usually see in many websites.Without submitting the whole form just u can check wther a username exist in the database or not =================================================-===== 1:filenames: index.php write a javascript fn like this in the head tag <script language="javascript"> function x() { var y=document.form1.t.value; ...
9
11298
by: Geoff Berrow | last post by:
Does anyone have a good regular expression snippet to validate usernames and passwords? -- Geoff Berrow (put thecat out to email) It's only Usenet, no one dies. My opinions, not the committee's, mine. Simple RFDs http://www.ckdog.co.uk/rfdmaker/
7
1522
by: Materialised | last post by:
Hi Folks, Just a quickie, I am inserting some records (individually) into a SQL Server Table. I am wondering how can I detect primary key violations on this data which I am inserting into the table. My Insert code is as follows (VB.Net): Public Function InsertNewUser(ByVal _ConnString As String, ByVal UserAccess As UserAccess.Access) As Integer
5
5750
by: olaamussah | last post by:
Hi, i just started learning perl which i would use for my uni. project unfortunately. Well, this is a simple user login page i tried to create but i cant get it to work. Can someone please check this out. Corrections would be highly appreciated. The code: use strict; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use DBI; $CGI::POST_MAX = 1024 * 1000; sub print_login_form($);
20
2386
by: cmbcorp | last post by:
Hi, I have been playing around with a simple php login script and im getting an error message when i attempt to log in with the username and password i set in the sql table. The error message is as follows: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/greenpos/public_html/test4/checklogin.php on line 28 Wrong Username or Password The code: <?php $host="localhost"; // Host name
15
8008
by: Yew12 | last post by:
I am trying to create a simple login for my webpage, but Im a bit of a novice and cannot see where Im going wrong any help would be much appreciated. I'm using an access database and ODBC. The code I have got is below; <?php $tbl_name="tblCustomer";
10
4970
by: Jason | last post by:
I want to create a simple program with Two buttons on the form. BUTTON 1 - BACKUP PREFS this will do the following: Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla \sitemanager.xml to this location: \\drake\pvt\%USERNAME%\FileZilla-Prefs\ BUTTON 2 - RESTORE PREFS this will do the opposite:
0
9856
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10916
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10598
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10657
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7836
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5684
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4071
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.