]> andersk Git - sql-web.git/commitdiff
use nicepass for batch signup passwords
authorJoe Presbrey <presbrey@mit.edu>
Tue, 24 Apr 2007 22:35:46 +0000 (22:35 +0000)
committerJoe Presbrey <presbrey@mit.edu>
Tue, 24 Apr 2007 22:35:46 +0000 (22:35 +0000)
git-svn-id: svn://presbrey.mit.edu/sql/web/dev@130 a142d4bd-2cfb-0310-9673-cb33a7e74f58

batch/signup.php
bin/nicepass.py [new file with mode: 0755]

index 50041296f75041e1d943c9ff7722046961c5405b..99785226b2b3dc2ce762eadf19bc86910f300094 100755 (executable)
@@ -8,6 +8,8 @@ require_once('batch.inc.php');
 
 $myUsername = $argv[1];
 $myUID = $argv[3];
+if ($myUID<100) exit('bad UID');
+
 $hescmd = "hesinfo $myUsername passwd";
 $hesinfo = explode(':', trim(exec($hescmd)));
 if (count($hesinfo)>=4) {
@@ -17,9 +19,8 @@ if (count($hesinfo)>=4) {
        $myName = $myUsername;
 }
 $myEmail = $myUsername.'@mit.edu';
-$myPassword = substr(md5(uniqid()),0,8);
-
-if ($myUID<100) exit('bad UID');
+$myPassword = trim(exec(dirname(__FILE__).'/../bin/nicepass.py'));
+if (empty($myPassword)) exit('bad Password');
 
 $Login = new Login($myUsername);
 if (!$Login->exists() && !empty($myUsername)) {
diff --git a/bin/nicepass.py b/bin/nicepass.py
new file mode 100755 (executable)
index 0000000..18219b5
--- /dev/null
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+
+def nicepass(alpha=6,numeric=2):
+    """
+    returns a human-readble password (say rol86din instead of
+    a difficult to remember K8Yn9muL )
+    """
+    import string
+    import random
+    vowels = ['a','e','i','o','u']
+    consonants = [a for a in string.ascii_lowercase if a not in vowels]
+    digits = string.digits
+
+    def a_part(slen):
+        ret = ''
+        for i in range(slen):
+            if i%2 ==0:
+                randid = random.randint(0,20) #number of consonants
+                ret += consonants[randid]
+            else:
+                randid = random.randint(0,4) #number of vowels
+                ret += vowels[randid]
+        return ret
+
+    def n_part(slen):
+        ret = ''
+        for i in range(slen):
+            randid = random.randint(0,9) #number of digits
+            ret += digits[randid]
+        return ret
+
+    fpl = alpha/2
+    if alpha % 2 :
+        fpl = int(alpha/2) + 1
+    lpl = alpha - fpl
+
+    start = a_part(fpl)
+    mid = n_part(numeric)
+    end = a_part(lpl)
+
+    return "%s%s%s" % (start,mid,end)
+
+if __name__ == "__main__":
+    print nicepass()
This page took 0.041766 seconds and 5 git commands to generate.