[vhffs-dev] [2130] mail boxes are now using sha512 as well

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 2130
Author:   gradator
Date:     2012-03-08 21:26:34 +0100 (Thu, 08 Mar 2012)
Log Message:
-----------
mail boxes are now using sha512 as well

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Services/Mail.pm

Modified: trunk/vhffs-api/src/Vhffs/Services/Mail.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Mail.pm	2012-03-07 22:50:51 UTC (rev 2129)
+++ trunk/vhffs-api/src/Vhffs/Services/Mail.pm	2012-03-08 20:26:34 UTC (rev 2130)
@@ -55,11 +55,18 @@
 use Vhffs::Functions;
 use Vhffs::Services::MailingList;
 
-#Following function is needed by courier to fetch accounts
-sub crypt_pwd {
-	my $clear = shift;
-	my $salt  = join '', ('.', '/', 0..9,'A'..'Z', 'a'..'z')[rand 64, rand 64];
-	return crypt( $clear , $salt );
+=pod
+
+=head2 password_encrypt
+
+my $encryptedpass = Vhffs::Services::Mail::password_encrypt( $pass );
+
+Returns a sha512 crypt password from plain text password. Salt is randomized.
+
+=cut
+sub password_encrypt {
+	my $password = shift;
+	return crypt($password, '$6$'.join( '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[map {rand 64} (1..16)]) );
 }
 
 =pod address_exists
@@ -301,7 +308,7 @@
 
 	return -1 unless defined $self->{'boxes'}{$local_part};
 
-	$password = crypt_pwd( $password );
+	$password = password_encrypt( $password );
 
 	$self->{'boxes'}{$local_part}{'password'} = $password;
 
@@ -526,7 +533,7 @@
 	return -2 if( ( defined ( $self->{'boxes'}{$name} ) ) || ( defined( $self->{'forward'}{$name} ) )
 		|| Vhffs::Services::MailingList::address_exists($self->get_vhffs, $name, $self->{domain}) );
 
-	$password = crypt_pwd( $password );
+	$password = password_encrypt( $password );
 	my $domainhash = $self->{boxes_path};
 	my $userhash = substr( $name, 0, 1 ).'/'.$name;
 	$self->{'boxes'}{$name}{'local_part'} = $name;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/