aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorm.fu <m_fu@310415.no-reply.drupal.org>2009-03-26 22:15:29 +0000
committerm.fu <m_fu@310415.no-reply.drupal.org>2009-03-26 22:15:29 +0000
commit6a47694344b17d7498d390ca11354f3370cd6416 (patch)
treee35ff8f1687877385a2b095694fccf166bb8439a
parent417906cee68e675b9ced096c458071aa4122682d (diff)
downloaddrupal_htpasswdsync-6a47694344b17d7498d390ca11354f3370cd6416.tar.gz
drupal_htpasswdsync-6a47694344b17d7498d390ca11354f3370cd6416.tar.bz2
drupal_htpasswdsync-6a47694344b17d7498d390ca11354f3370cd6416.zip
Added #408798 by fasdalf@fasdalf.ru : request for windows support
windows does not support crypt password hash added support for SHA-1 password hash which is supported by windows. Fixed : group file not allways updated.
-rw-r--r--CHANGELOG.txt4
-rw-r--r--HTPasswdSync.module69
2 files changed, 70 insertions, 3 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index b4cc73c..f3f1beb 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -2,5 +2,9 @@ $Id$
v1.1-Dev bug fix release
Fixed #409406 by fasdalf@fasdalf.ru : remove comma in htgroup file
+Added #408798 by fasdalf@fasdalf.ru : request for windows support
+ windows does not support crypt password hash
+ added support for SHA-1 password hash which is supported by windows.
+Fixed : group file not allways updated.
v1.0 Initial release \ No newline at end of file
diff --git a/HTPasswdSync.module b/HTPasswdSync.module
index 7945816..d7cb615 100644
--- a/HTPasswdSync.module
+++ b/HTPasswdSync.module
@@ -1,7 +1,13 @@
-?php
+<?php
// $Id$
/*
* $Log$
+ * Revision 1.1.2.2 2009/03/26 22:15:29 mfu
+ * Added #408798 by fasdalf@fasdalf.ru : request for windows support
+ * windows does not support crypt password hash
+ * added support for SHA-1 password hash which is supported by windows.
+ * Fixed : group file not allways updated.
+ *
* Revision 1.1.2.1 2009/03/25 19:24:10 mfu
* Fixed #409406 by fasdalf@fasdalf.ru : remove comma in htgroup file
*
@@ -48,6 +54,55 @@
function _htpasswdsync_roles() {
return variable_get('htpasswdsync_roles', array());
}
+
+
+ /**
+ * return array of available hashes
+ *
+ * return an array of possible hashes
+ *
+ * @return
+ * array
+ */
+ function _htpasswdsync_hashes() {
+ return array ('crypt', 'SHA-1');
+ }
+
+ /**
+ * return hash algorithm name
+ *
+ * return the name of the hash algorithm to use for password
+ * hashing
+ *
+ * @return
+ * string ('crypt', 'SHA-1')
+ */
+ function _htpasswdsync_hash() {
+ return variable_get('htpasswdsync_hash', 0);
+ }
+
+ /**
+ * crypt password
+ *
+ * return the password hashed according to users preferences
+ *
+ * @param $password
+ * the password, as a string, to encrypt
+ * @return
+ * encrpyted password (actually hashed)
+ */
+ function _htpasswdsync_crypt($password) {
+ $hashes = _htpasswdsync_hashes();
+ switch ($hashes[_htpasswdsync_hash()]) {
+ case 'crypt':
+ return crypt($password, chr(rand(65, 122)) . chr(rand(65, 122)));
+ break;
+ case 'SHA-1':
+ return '{SHA}' . base64_encode(sha1($password, TRUE));
+ break;
+ }
+ return _htpasswdsync_hash();
+}
/**
* read an htfile
@@ -169,7 +224,7 @@
// update with the $account information received
// password crypted with the standard crypt (not MD5) function
$user = $account['name'];
- $pass = crypt($account['pass'], chr(rand(65, 122)) . chr(rand(65, 122)));
+ $pass = _htpasswdsync_crypt($account['pass']);
$passwds[$user] = $pass;
//save file
@@ -178,6 +233,7 @@
//update table
db_query("DELETE FROM {htpasswdsync_passwd} WHERE username = '%s'", $user);
db_query("INSERT INTO {htpasswdsync_passwd} (username, passwd) VALUES('%s', '%s')", $user, $pass);
+ _htpasswdsync_updategroup();
}
/* remove the user for the htpassword file
@@ -267,7 +323,14 @@ function htpasswdsync_admin() {
array('!file' => 'htgroup')),
'#required' => TRUE,
);
- $form['htpasswdsync_roles'] = array(
+ $form['htpasswdsync_hash'] = array(
+ '#type' => 'radios',
+ '#title' => t('password hashing algorythm'),
+ '#description' => t("How shall the password be hashed (crypt for unix, SHA1 for all)"),
+ '#options' => _htpasswdsync_hashes(),
+ '#default_value' => _htpasswdsync_hash(),
+ );
+ $form['htpasswdsync_roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Roles to be exported in htgroup'),
'#default_value' => _htpasswdsync_roles(),

© 2014-2024 Faster IT GmbH | imprint | privacy policy