Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: What *are* the best ways to encrypt data?

by neilwatson (Priest)
on Aug 27, 2004 at 13:30 UTC ( [id://386361]=note: print w/replies, xml ) Need Help??


in reply to Re^2: What *are* the best ways to encrypt data?
in thread What *are* the best ways to encrypt data?

I have a module to do this for a couple of websites:
########################### # use mapps; # # CREATE TABLE users ( # auid int(10) unsigned NOT NULL auto_increment, # auname varchar(30) default NULL, # PRIMARY KEY (auid) # ) TYPE=MyISAM; # # CREATE TABLE secrets ( # auid int(10) unsigned NOT NULL auto_increment, # passwd char(40) NOT NULL default '', # salt int(11) NOT NULL default '0', # PRIMARY KEY (auid) # ) TYPE=MyISAM DEFAULT; ########################## package Mapps::Auth; use Exporter; use Digest::SHA1; use DBI; use warnings; use strict; use vars qw($VERSION @ISA @EXPORT); our $VERSION = 1.00; our @ISA = qw(Exporter); our @EXPORT = qw(&new &auth); sub new { my $class = shift; my $self = {}; return bless $self, $class; } sub auth { my ($self, $dbh1); my $uname = shift; my $passwd = shift; my ($dbsecret, $salt, $uid); $dbh1 = DBI->connect('dbi:mysql:itiv', 'lwriter', '**I can't tell +you!') or die "Couldn't connect: $dbh1->errstr"; # get secret from db my $statement="SELECT admin_users.auid, auname, passwd, salt FROM admin_users, secrets WHERE admin_users.auid=secrets.auid AND auname='$uname';"; my $sth = $dbh1->prepare($statement) or die "Couldn't prepare stat +ement: ".$dbh1->errstr; $sth->execute or die "Couldn't execute statement: ".$dbh1->errstr; while (my $ref = $sth->fetchrow_hashref){ $dbsecret = $ref->{'passwd'}; $salt = $ref->{'salt'}; $uid = $ref->{'auid'}; } # encrypts password using # SHA-1 algorithm my $sha1 = Digest::SHA1->new; # reset algorithm $sha1->hexdigest; # encrypt my $secret = Digest::SHA1::sha1_hex($passwd . $salt); #die "$uid, $dbsecret, $secret, $salt "; # does generated secret match database secret? if ($secret eq $dbsecret){ return (1, $uid); } return (0, $uid); } 1;

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re^4: What *are* the best ways to encrypt data?
by bradcathey (Prior) on Aug 27, 2004 at 13:41 UTC

    Thanks, Neil for sharing that. I will take a closer look.


    —Brad
    "Don't ever take a fence down until you know the reason it was put up." G. K. Chesterton

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://386361]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-19 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found