Crypt-MySQL-0.04/0000755000076500007650000000000010470050072013666 5ustar ikebeikebe00000000000000Crypt-MySQL-0.04/Build.PL0000644000076500007650000000066510470037552015201 0ustar ikebeikebe00000000000000use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'Crypt::MySQL', license => 'perl', dist_author => 'Tomohiro IKEBE ', dist_version_from => 'lib/Crypt/MySQL.pm', requires => { 'Test::More' => 0, 'Digest::SHA1' => 0, }, add_to_cleanup => [ 'Crypt-MySQL-*' ], ); $builder->create_build_script(); Crypt-MySQL-0.04/Changes0000644000076500007650000000057410470050032015163 0ustar ikebeikebe000000000000002006-08-14 IKEBE Tomohiro * added password41() to @EXPORT_OK list. * support MySQL 4.1's PASSWORD() function. * allow the string which contain Null characters. Apply the patch from Zefram. 2004-02-24 IKEBE Tomohiro * fixed array overrun problem. 2003-04-24 IKEBE Tomohiro * original version Crypt-MySQL-0.04/lib/0000755000076500007650000000000010470050072014434 5ustar ikebeikebe00000000000000Crypt-MySQL-0.04/lib/Crypt/0000755000076500007650000000000010470050072015535 5ustar ikebeikebe00000000000000Crypt-MySQL-0.04/lib/Crypt/MySQL.pm0000644000076500007650000000217510470037636017060 0ustar ikebeikebe00000000000000package Crypt::MySQL; use strict; use vars qw($VERSION @ISA @EXPORT_OK); use Digest::SHA1 qw(sha1 sha1_hex); BEGIN { $VERSION = '0.04'; if ($] > 5.006) { require XSLoader; XSLoader::load(__PACKAGE__, $VERSION); } else { require DynaLoader; @ISA = qw(DynaLoader); __PACKAGE__->bootstrap; } require Exporter; push @ISA, 'Exporter'; @EXPORT_OK = qw(password password41); } sub password41($) { "*".uc(sha1_hex(sha1($_[0]))); } 1; __END__ =head1 NAME Crypt::MySQL - emulate MySQL PASSWORD() function. =head1 SYNOPSIS use Crypt::MySQL qw(password password41); my $encrypted = password("foobar"); # for MySQL 3.23, 4.0 my $encrypted = password41("foobar"); # for MySQL 4.1 or later. =head1 DESCRIPTION Crypt::MySQL emulates MySQL PASSWORD() SQL function, without libmysqlclient. You can compare encrypted passwords, without real MySQL environment. =head1 AUTHOR IKEBE Tomohiro Eikebe@shebang.jpE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L L =cut Crypt-MySQL-0.04/lib/Crypt/MySQL.xs0000644000076500007650000000234710470015375017073 0ustar ikebeikebe00000000000000#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include typedef unsigned long ulong; typedef unsigned char uchar; void __crypt_mysql_hash_password(ulong *result, const char *password, size_t password_len) { const char *password_end = password + password_len; register ulong nr=1345345333L, add=7, nr2=0x12345671L; ulong tmp; for (; password != password_end ; password++) { if (*password == ' ' || *password == '\t') continue; /* skipp space in password */ tmp= (ulong) (uchar) *password; nr^= (((nr & 63)+add)*tmp)+ (nr << 8); nr2+=(nr2 << 8) ^ nr; add+=tmp; } result[0]=nr & (((ulong) 1L << 31) -1L); /* Don't use sign bit (str2int) */; result[1]=nr2 & (((ulong) 1L << 31) -1L); return; } void __crypt_mysql_make_scrambled_password(char *to, const char *password, size_t password_len) { ulong hash_res[2]; __crypt_mysql_hash_password(hash_res,password,password_len); sprintf(to,"%08lx%08lx",hash_res[0],hash_res[1]); } MODULE = Crypt::MySQL PACKAGE = Crypt::MySQL SV * password(str) SV *str; CODE: { char to[17]; STRLEN size; char *src = SvPV(str, size); __crypt_mysql_make_scrambled_password(to, src, size); RETVAL = newSVpv(to, 0); } OUTPUT: RETVAL Crypt-MySQL-0.04/Makefile.PL0000644000076500007650000000105510470037544015652 0ustar ikebeikebe00000000000000use strict; use warnings; use ExtUtils::MakeMaker; link("lib/Crypt/MySQL.xs", "MySQL.xs"); WriteMakefile( NAME => 'Crypt::MySQL', AUTHOR => 'Tomohiro IKEBE ', VERSION_FROM => 'lib/Crypt/MySQL.pm', ABSTRACT_FROM => 'lib/Crypt/MySQL.pm', PL_FILES => {}, PREREQ_PM => { 'Test::More' => 0, 'Digest::SHA1' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Crypt-MySQL-*' }, ); Crypt-MySQL-0.04/MANIFEST0000644000076500007650000000035710470050072015024 0ustar ikebeikebe00000000000000Build.PL Changes lib/Crypt/MySQL.pm lib/Crypt/MySQL.xs Makefile.PL MANIFEST This list of files README t/00_compile.t t/01_password.t t/02_export.t t/03_dbi.t META.yml Module meta-data (added by MakeMaker) Crypt-MySQL-0.04/META.yml0000644000076500007650000000057410470050072015145 0ustar ikebeikebe00000000000000# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Crypt-MySQL version: 0.04 version_from: lib/Crypt/MySQL.pm installdirs: site requires: Digest::SHA1: 0 Test::More: 0 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.30 Crypt-MySQL-0.04/README0000644000076500007650000000204110470015375014552 0ustar ikebeikebe00000000000000Crypt-MySQL The README is used to introduce the module and provide instructions on how to install the module, any machine dependencies it may have (for example C compilers and installed libraries) and any other information that should be provided before the module is installed. A README file is required for CPAN modules since CPAN extracts the README file from a module distribution so that people browsing the archive can use it get an idea of the modules uses. It is usually a good idea to provide version information here so that people can decide whether fixes for the module are worth downloading. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install Alternatively, to install with Module::Build, you can use the following commands: perl Build.PL ./Build ./Build test ./Build install COPYRIGHT AND LICENCE Copyright (C) 2006 Tomohiro IKEBE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Crypt-MySQL-0.04/t/0000755000076500007650000000000010470050072014131 5ustar ikebeikebe00000000000000Crypt-MySQL-0.04/t/00_compile.t0000644000076500007650000000011010470015375016244 0ustar ikebeikebe00000000000000use strict; use Test::More tests => 1; BEGIN { use_ok 'Crypt::MySQL' } Crypt-MySQL-0.04/t/01_password.t0000644000076500007650000000031510470015704016462 0ustar ikebeikebe00000000000000use strict; use Test::More tests => 2; use Crypt::MySQL (); is(Crypt::MySQL::password("foobar"), "4655c05b05f11fab"); is(Crypt::MySQL::password41("foobar"), "*9B500343BC52E2911172EB52AE5CF4847604C6E5"); Crypt-MySQL-0.04/t/02_export.t0000644000076500007650000000030610470037616016150 0ustar ikebeikebe00000000000000use strict; use Test::More tests => 2; use Crypt::MySQL qw(password password41); is(password("barbaz"), "5256847878f9978f"); is(password41("barbaz"), "*096C6A6F0E3B0A35BFF7794D732F2269D6BBE164"); Crypt-MySQL-0.04/t/03_dbi.t0000644000076500007650000000164110470015375015367 0ustar ikebeikebe00000000000000use strict; use Test::More; use Crypt::MySQL (); unless (eval { require DBD::mysql } && eval { require DBI }) { plan skip_all => "no DBD::mysql"; } else { plan tests => 1; } SKIP: { my $dbh = eval { DBI->connect("dbi:mysql:test", "root", "", { RaiseError => 1, PrintError => 1 }); }; skip "could not connect to MySQL", 1 unless $dbh; my $tm = time. ""; my $sth = $dbh->prepare("SELECT PASSWORD(?)"); $sth->execute($tm); my($real_mysql) = $sth->fetchrow_array; $sth->finish; my $sth2 = $dbh->prepare('SELECT VERSION()'); $sth2->execute; my($verstr) = $sth2->fetchrow_array; $sth2->finish; $dbh->disconnect; my($ver) = $verstr =~ m/^([0-9]+\.[0-9]+)/; if ($ver >= 4.1) { is($real_mysql, Crypt::MySQL::password41($tm)); } else { is($real_mysql, Crypt::MySQL::password($tm)); } }