Egg::Model::Auth::Crypt::Func - AUTH component to treat code of attestation data by standard function.


Egg-Release-Authorize documentation Contained in the Egg-Release-Authorize distribution.

Index


Code Index:

NAME

Top

Egg::Model::Auth::Crypt::Func - AUTH component to treat code of attestation data by standard function.

SYNOPSIS

Top

  package MyApp::Model::Auth::MyAuth;
  ..........

  __PACKAGE__->config(
    crypt_func_md5 => '$1$abcd1234',
    );

  __PACKAGE__->setup_api( File => qw/ Crypt::Func / );

DESCRIPTION

Top

It is API component to treat the password in the attestation data by function crypt of the Perl standard.

'Crypt::Func' is included in the list following API component name specified for 'setup_api' method.

  __PACKAGE__->setup_api( DBI => qw/ Crypt::Func / );

When the character of 11 digits that starts from '$1$' is set to 'crypt_func_md5' of the configuration, the code comes to be treated with MD5.

METHODS

Top

password_check ([CRYPT_PASSWORD], [INPUT_PAWWORD])

The agreement of CRYPT_PASSWORD and INPUT_PAWWORD is confirmed.

create_password ([PLAIN_PASSWORD])

PLAIN_PASSWORD is encrypted.

SEE ALSO

Top

Egg::Release, Egg::Model::Auth, Egg::Model::Auth::Base::API,

AUTHOR

Top

Masatoshi Mizuno <lushe&64;cpan.org>

COPYRIGHT AND LICENSE

Top


Egg-Release-Authorize documentation Contained in the Egg-Release-Authorize distribution.

package Egg::Model::Auth::Crypt::Func;
#
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
#
# $Id: Func.pm 347 2008-06-14 18:57:53Z lushe $
#
use strict;
use warnings;
use Carp qw/ croak /;

our $VERSION= '0.01';

sub _setup {
	my($class, $e)= @_;
	if (my $salt= $class->config->{crypt_func_md5}) {
		$salt= '$1$'. $salt unless $salt=~m{^\$1\$};
		length($salt)== 11 or die q{As for 'crypt_func_md5',}
		. q{ I want you to set it by 11 characters that start by '$1$'.};
		$class->config->{crypt_func_md5}= $salt;
	}
	$class->next::method($e);
}
sub password_check {
	my $self = shift;
	my $crypt= shift || croak 'I want crypt string.';
	my $password= shift || croak 'I want password.';
	   $crypt=~s{^\s+} []; $crypt=~s{\s+$} [];
	   $password=~s{^\s+} []; $password=~s{\s+$} [];
	crypt($password, $crypt) eq $crypt ? 1: 0;
}
sub create_password {
	my $self    = shift;
	my $password= shift || croak 'I want password.';
	   $password=~s{^\s+} []; $password=~s{\s+$} [];
	my $salt= $self->config->{crypt_func_md5} || do {
		my @tmp= ('A'..'Z', 'a'..'z', '.', '/');
		$tmp[int rand(@tmp)]. $tmp[int rand(@tmp)];
	  };
	crypt($password, $salt);
}

1;

__END__