Updating MT to play well with Atom

While cobbling together an Atom implementation for MovableType, I've had to change how passwords are stored. After a quick email from Mark, I changed lib/MT/Author.pm slightly to make the passwords stored in a manner more friendly to the current Atom Authentication Scheme, and allow easy migration of current passwords.

Here is the diff:

--- Author.pm.old       Thu May 29 00:04:58 2003
+++ Author.pm   Thu Sep 11 09:13:48 2003
@@ -6,6 +6,8 @@
 package MT::Author;
 use strict;

+use Digest::SHA1 qw( sha1_hex );
+
 use MT::Object;
 @MT::Author::ISA = qw( MT::Object );
 __PACKAGE__->install_properties({
@@ -25,9 +27,8 @@
 sub set_password {
     my $auth = shift;
     my($pass) = @_;
-    my @alpha = ('a'..'z', 'A'..'Z', 0..9);
-    my $salt = join '', map $alpha[rand @alpha], 1..2;
-    $auth->column('password', crypt $pass, $salt);
+    $auth->column ('password',
+       sha1_hex (join (':', $auth->column ('name'), 'MovableType', $pass)));
 }

 sub is_valid_password {
@@ -35,8 +36,15 @@
     my($pass, $crypted) = @_;
     $pass ||= '';
     my $real_pass = $auth->column('password');
-    return $crypted ? $real_pass eq $pass :
-                      crypt($pass, $real_pass) eq $real_pass;
+    return 1 if ($crypted ? $pass eq $real_pass :
+       sha1_hex (join (':', $auth->column ('name'), 'MovableType', $pass))
+       eq $real_pass);
+    if (crypt ($pass, $real_pass) eq $real_pass) {
+      $auth->set_password ($pass);
+      return 1;
+    }
+
+    return 0;
 }

 sub remove {

Leave a comment

Recent Entries

  • Plugin Writing 101

    So, I’m planning on writing up some entries about various aspects of plugin development. While I have a couple topics already in mind, I thought...

  • The Olympics Make Me Want To Compete Again

    Every time the Olympics come around (most the summer ones) I always start to delude myself into thinking I could complete once again in the...

  • Minimalist plugins are fun!

    Last night I whipped up one of the smallest plugins I’ve ever written. It is so small in fact that I was able to stuff...

  • Feedburner Widget on MT News

    Movable Type News A WordPress 2.5 Upgrade Guide: And of course there are lots of third-party plugins for the MT dashboard, to integrate statistics and...

  • AD&D Monster Stats for the Presidential Canditates

    Charles Stross (scifi author, D&D nerd, and former perl columnist) posted Politics as she is Played with 3d6: The recent death of Gary Gygax, who...

Close