1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
# Movable Type (r) Open Source (C) 2001-2012 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id$
package MT::BasicAuthor;
# fake out the require for this package since we're
# declaring it inline...
use base qw( MT::Object );
__PACKAGE__->install_properties(
{ column_defs => {
'id' => 'integer not null auto_increment',
'name' => 'string(50) not null',
'password' => 'string(124) not null',
'email' => 'string(75)',
'hint' => 'string(75)',
},
indexes => {
name => 1,
email => 1,
},
datasource => 'author',
primary_key => 'id',
}
);
sub nickname {
my $author = shift;
$author->name;
}
sub is_valid_password {
my $author = shift;
my ( $pass, $crypted, $error_ref ) = @_;
$pass ||= '';
require MT::Auth;
return MT::Auth->is_valid_password( $author, $pass, $crypted,
$error_ref );
}
sub set_password {
my $auth = shift;
my ($pass) = @_;
my @alpha = ( 'a' .. 'z', 'A' .. 'Z', 0 .. 9 );
my $salt = join '', map $alpha[ rand @alpha ], 1 .. 16;
my $crypt_sha;
if ( eval { require Digest::SHA } ) {
# Can use SHA512
$crypt_sha = '$6$' . $salt . '$' . Digest::SHA::sha512_base64( $salt . $pass );
}
else {
# Use SHA-1 algorism
$crypt_sha = '{SHA}' . $salt . '$' . MT::Util::perl_sha1_digest_hex( $salt . $pass );
}
$auth->column( 'password', $crypt_sha );
}
sub magic_token {
my $auth = shift;
require MT::Util;
my $pw = $auth->column('password');
if ( $pw eq '(none)' ) {
$pw
= $auth->id . ';'
. $auth->name . ';'
. ( $auth->email || '' ) . ';'
. ( $auth->hint || '' );
}
require MT::Util;
MT::Util::perl_sha1_digest_hex($pw);
}
# trans('authors');
1;
__END__
=head1 NAME
MT::BasicAuthor
=head1 METHODS
=head2 $author->is_valid_password($pass, $crypted, $error_ref)
Return the value of L<MT::Auth/is_valid_password>
=head2 $author->set_password
Set the I<$author> password with the perl C<crypt> function.
=head2 $author->magic_token()
Return the value of L<MT::Util/perl_sha1_digest_hex> for the I<password> column.
=head1 AUTHOR & COPYRIGHT
Please see L<MT/AUTHOR & COPYRIGHT>.
=cut
|