473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

question of whether authentication of password and username is good

170 100+
hey guys
i got the code below to authenticate users for database

Expand|Select|Wrap|Line Numbers
  1. #!perl\bin\perl
  2.  
  3. use strict;
  4. use warnings;
  5. use DBI();
  6.  
  7. my $dbh;
  8. my $sth; 
  9. my $name1;
  10. my $name2;
  11.  
  12. print STDOUT"Select the name of your database: ";
  13. my $database=<STDIN>;
  14. chop($database);
  15. print STDOUT "Enter your hostname: ";
  16. my $hostname=<STDIN>;
  17. chop($hostname);
  18. print STDOUT"Enter your username: ";
  19. my $username=<STDIN>;
  20. chop($username);
  21. print STDOUT "Enter your password: ";
  22. my $password=<STDIN>;
  23. chop($password);
  24.  
  25.  
  26. $dbh = DBI->connect("DBI:mysql:database=$database;host=$hostname","$username","$password", 
  27.                     {RaiseError => 1});
  28.  
  29.  
  30. $sth = $dbh ->prepare("SELECT * FROM `user account` WHERE Username='$username'");
  31. $sth->execute();
  32. while (my $ref =$sth->fetchrow_hashref()) {
  33. $name1 = $ref->{'Username'}, $name2 = $ref->{'Password'};}
  34. print "$name1\n";
  35.  
  36. if ($username eq "$name1" && $password eq "$name2") {
  37.   print "login successful\n";}
  38. else {
  39.  
  40.   print "login unsuccessful\n";}
  41.  
  42. $dbh->disconnect();
  43.  
u might be wondering why i need to authenticate when SQL itself can authenticate the users and password
i'm doing this as i gonna connect this to a telnet session
i created a database to categorise users according to the type of commands they can type in the telnet sessions later on
so i'm wondering if such a technique of authenfying...is it alright?
Apr 25 '08 #1
2 1436
KevinADC
4,059 Expert 2GB
Should be OK like you have it.

Don't get into the habit of quoting scalars needlessly:

Expand|Select|Wrap|Line Numbers
  1. if ($username eq "$name1" && $password eq "$name2") {
better written as:

Expand|Select|Wrap|Line Numbers
  1. if ($username eq $name1 && $password eq $name2) {
It is inefficient and can create hard to find bugs.
Apr 26 '08 #2
poolboi
170 100+
Should be OK like you have it.

Don't get into the habit of quoting scalars needlessly:

Expand|Select|Wrap|Line Numbers
  1. if ($username eq "$name1" && $password eq "$name2") {
better written as:

Expand|Select|Wrap|Line Numbers
  1. if ($username eq $name1 && $password eq $name2) {
It is inefficient and can create hard to find bugs.
thanks a lot for your help :)
Apr 28 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Phil Powell | last post by:
/*-------------------------------------------------------------------------------------------- This function will utilize the ability to use HTTP-based WWW Authentication, checking for the global...
7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
0
by: Michael B. Murdock | last post by:
I have been attempting to find a script that works in a variety of AD implementations to authenticate a user from a form in ASP. After many failed attempts I developed the following test script...
6
by: Magnus Jardeby | last post by:
I have a problem with basic authentication. I redirect a user from a page to another. I don't want to get the NT prompt login, I want the user to be logged in automatically. I want to send the...
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
7
by: Nikolay Petrov | last post by:
Can I authenticate users of my ASP .NET apps, using their windows credentials, but using a SQL db. Let me explain a little more. I have an Windows XP station where i run my ASP .NET apps. I wish...
2
by: P Webster | last post by:
We recently moved a web site that validated user credentials in Active Directory from IIS 5.1 to IIS 6, and the validation code no longer works. The web.config file is set to Windows authentication...
18
by: =?Utf-8?B?VG9t?= | last post by:
is it possible to add a bunch of users to group and only allow group to access the web page or do I need to add each user to the web.config file? Or is there another way to do this? I just took...
3
by: Genius79 | last post by:
Hi I'm trying to do an ASP authentication using Ldap and would like to have the users directed to pages based on the Organizational Unit. My ASP knowledge is pretty basic but would really like to get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...

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.