Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Simple User validation

Posted on 2000-02-28
7
Medium Priority
?
162 Views
Last Modified: 2013-12-24
I need users to veiw specific pages on my site, the pages they view depend on the User Name and password they use. I need this to be as simple as possible, without the use of databases etc.. The data is not particularly sensitive so the solution doesn't have to be very secure. I need the quick fix to prove to investors that the site works.

Any help would be much appreciated
0
Comment
Question by:gids_w
7 Comments
 
LVL 6

Expert Comment

by:Marine
ID: 2566960
ok the problem you going to have is this. Every user that comes on the site must have the same password then as all other users. THen you simple check if the password he entered is the same as it's in hardcoded then you allow him to acces the site. Something like this.
<% If password = request.form("psw") then
   response.redirect "game.htm"
   end if
%>
0
 
LVL 3

Expert Comment

by:fibdev
ID: 2566984
I think a simple text database with a cgi script is the way to go.  You could store the username, password, and url in the database, when the username is entered, the cgi-script compares the data to see if the password matches, then redirects to the url.
0
 
LVL 3

Expert Comment

by:fibdev
ID: 2567022
The form might look something like this:

<form name="chkusr" method="post" action="../cgi-bin/usrdata.db">
  <p align="left">
  Username:&bnsp;<input name="user"><br>
  Password:&bnsp;<input name="pass"><br>
  <br>
  <br>
  <input type="submit" name="submit" value="submit">
  </p>
</form>


The datafile might be named "usrdata.db" and look something like this:

user1, password, http://fibdev.com
user2, password, http://www.experts-exchange.com
user3, password, http://www.download.com


Lastly, the cgi script may look something like this:

#!/usr/bin/perl
#
#
# Search user file and produce results
# Author: G. M. Faggiano
# Copyright 2000 Fibdev Software, Inc.
# All rights reserved
#
#
$datafile = "/www/cgi-bin/usrdata.db";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $value =~ s/~!/ ~!/g;
    $FORM{$name} = $value;
}

$searchstr = $FORM{'username'};

open(INF,$datafile);
@mydata = <INF>;
close(INF);
@results = grep(/$searchstr/i,@mydata);
print "Content-type:text/html\n\n";

if ($#results >= 0) {
    foreach $i (@results) {
      chomp($i);
      ($username, $password, $url) = split(/\|/,$i);

if $form{'password'} <> $password then
print "Incorrect password"
print "<a href="javascript:history(-1)>Back</a>

If $form{'password'} == $password then
sub MoveToWelcom {
      print "Location:$url \n\n";
            }

    }
} else {
    print "No results found.<p>\n";
}


There are probably serveral errors in this script, I didn't check it and perl is not my strong suit by any means.  This is just to give you an idea and if you show it to someone who knows perl, they can probably correct it or re-write it to suit your needs.

Good luck
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 3

Expert Comment

by:fibdev
ID: 2567058
Fixes for the query cgi (still not free of bugs, recommend having it looked at)

#!/usr/bin/perl
#
#
# Search user file and produce results
# Author: G. M. Faggiano
# Copyright 2000 Fibdev Software, Inc.
# All rights reserved
#
#
$datafile = "/www/cgi-bin/usrdata.db";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $value =~ s/~!/ ~!/g;
    $FORM{$name} = $value;
}

$searchstr = $FORM{'user'};

open(INF,$datafile);
@mydata = <INF>;
close(INF);
@results = grep(/$searchstr/i,@mydata);
print "Content-type:text/html\n\n";

<<EndHTML
<html>
<head>
<title></title>
</head>
<body>
EndHTML;
if ($#results >= 0) {
    foreach $i (@results) {
chomp($i);
($user, $pass, $url) = split(/\|/,$i);

if $form{'password'} <> $pass then
print "Incorrect password"
print "<a href="javascript:history(-1)>Back</a>

If $form{'password'} == $pass then
sub MoveToWelcome {
print "Location:$url \n\n";
}

    }
} else {
    print "No results found.<p>\n";
}

<<EndHTML
</body>
</html>
EndHTML;





Use this one to write to the db file:

#!/usr/bin/perl
#=================================
# Data Entry Cgi
#=================================
print "Content-type:text/html\n\n";

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    $value =~ s/\n/ /g;# added to strip line breaks

    $FORM{$name} = $value;
}

open(OUTF,">>/www/cgi-bin/usrdata.db") or dienice("Couldn't open
usrdata.db for writing: $!");

    print OUTF "$FORM{'user'}|$FORM{'pass'}|$FORM{'url'}\n";

    close(OUTF);


print <<EndHTML;
<html>
<head>
<title>Thank You</title>
</head>
<body link="#FFFFFF" vlink="#FFFFFF" alink="#00FFFF" bgcolor="#C0C0C0">
<h4>Thank You!</h4><br>
<hr size="1" width="80%"><br>
<p>Your entry has been added<br><br>
<a href="javascript:history.back(1)">Add another entry?</a><br>
</p>
</body></html>
EndHTML

sub dienice {
    my($msg) = @_;
    print "<h2>Error</h2>\n";
    print $msg;
    exit;
}

0
 

Accepted Solution

by:
mandyf earned 412 total points
ID: 2575664
Hi gids w,

This is simple javascript to validation of user name and password. Hope to userful to you.

<HTML>
<HEAD>
<TITLE>Password protection</TITLE>
<SCRIPT language="javascript">
<!-- hide javascript from old browser
var password = prompt("Input your password !","")

if (password == 'abc') {
self.location = 'ok.html'
}

else {
self.location = 'wrong.html'
}

// done hiding -->
</SCRIPT>
<HEAD>
<BODY bgcolor="#ffffff"> </BODY>
</HTML>
0
 
LVL 1

Author Comment

by:gids_w
ID: 2590995
Adjusted points to 103
0
 
LVL 1

Author Comment

by:gids_w
ID: 2590996
Mandyf,
absolutely spot on, just what I needed, Thanks very much
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this short web based tutorial, I wanted to show users how they can still use the powers of FrontPage in conjunction with Expression Web 3.  Even though Microsoft eliminated the use of Web components, we can still use them with FrontPage and edit …
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question