/[smecontribs]/rpms/smeserver-dirty-tools/contribs7/smeserver-dirty-tools-0.0.9-usePasswordTools.patch
ViewVC logotype

Contents of /rpms/smeserver-dirty-tools/contribs7/smeserver-dirty-tools-0.0.9-usePasswordTools.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Sat Mar 1 17:19:10 2008 UTC (16 years, 8 months ago) by mweinber
Branch: MAIN
CVS Tags: smeserver-dirty-tools-0_0_9-2_el4_sme
use esmith::PasswordTools

1 --- smeserver-dirty-tools-0.0.9/root/sbin/e-smith/dt-pw-generate.usePasswordTools 2008-03-01 18:14:05.000000000 +0100
2 +++ smeserver-dirty-tools-0.0.9/root/sbin/e-smith/dt-pw-generate 2008-03-01 18:15:09.000000000 +0100
3 @@ -1,19 +1,12 @@
4 #!/usr/bin/perl
5 -# (C) 2005-2007 Michael Weinberger
6 -# See http://wiki.contribs.org/Dirty_Tools for full documentation
7 -
8 -
9 -# Copyright 2000 - 2004 George Shaffer
10 -#
11 -# Anyone may use or modify this code for any purpose PROVIDED
12 -# that as long as it is recognizably derived from this code,
13 -# that this copyright notice, remains intact and unchanged.
14 -# No warrantees of any kind are expressed or implied.
15
16 +# (C) 2005-2008 Michael Weinberger
17 +# See http://wiki.contribs.org/Dirty_Tools for full documentation
18
19 use strict;
20 use esmith::ConfigDB;
21 use esmith::FormMagick;
22 +use esmith::PasswordTools;
23 use Getopt::Long;
24
25 my %opts;
26 @@ -30,262 +23,7 @@
27 print "Usage: dt-pw-generate [--length=N] [--mixed-case] [--add-consonants]\n";
28 exit 0;
29 }
30 -
31 -
32 -
33 -BEGIN {
34 - srand(time() ^ ($$ + $$ << 21));
35 -}
36 -
37 -
38 -# siz
39 -# Increase the default 8 to change the generated password size
40 -# and extra letters will be added to the end. Decrease and
41 -# you'll lose some or all of the second string of letters.
42 -# Depending on the value of $addConsonants the actual
43 -# password length may range from $siz to $siz + 2.
44 -# Size interacts with other choices. If $addConsonants is false
45 -# size will be fixed length and is achieved by truncation after
46 -# checking for upper case and digits so short sizes (3 - 5) may
47 -# not have the variability you desire.
48 -#
49 -# addConsonants yes|no
50 -# Change $addConsonants to 'no' to prevent some extra consonants
51 -# from being tacked on to letter sequences. Leave $addConsonants
52 -# at 'yes' to sometimes add an extra consonant to letter sequences.
53 -# If left at 'yes' the password size will vary from $siz to $siz+2.
54 -#
55 -# firstUpper yes|no
56 -# Change $firstUpper to 'no' to prevent the first character of each
57 -# letter sequence from being upper case. Leave it as 'yes' if you
58 -# want some of the first characters to be upper case.
59 -#
60 -# mixedCase yes|no
61 -# Change $mixedCase to 'yes' to mix the case of all letters.
62 -# $mixedCase is not random as subsequent checks force at
63 -# least one upper and one lower case letter in each password.
64 -# Leave it at 'no' so all letters will be lower case or only
65 -# the first or each letter sequence may be upper case.
66 -#
67 -# symbolOdds
68 -# By changing $symbolOdds from 0 to 10 you change the likelihood
69 -# of having two numbers or a number and a symbol. At 0 you will
70 -# always get 2 digits. At 1 you will usually only get one digit
71 -# but will sometimes get a second digit or a symbol. At 10 you
72 -# will always get two numbers or a number and a symbol with the
73 -# about even chances that one of the two characters will be a
74 -# symbol. The odds are affected by what characters are added to
75 -# or removed from the $sym initialization string.
76 -# The default is 7.
77 -#
78 -# symbols
79 -# Add or remove symbols to make passwords easier or harder
80 -# to type. Delete the second set of digits to increase
81 -# the relative frequency of symbols and punctuation.
82 -# Add some vowels or consonants to really change the patterns
83 -# but these will also get much harder to remember.
84 -# The $ needs to be escaped if it is to be available as a
85 -# password character.
86 -# Default is ',.<>~`!@#$%^&*()-_+='
87 -
88 -
89 -sub sme_generate_password( $$$ )
90 - {
91 - my ( $siz, $addConsonants, $mixedCase ) = @_;
92 - my $symbols = ",.!@#\$%&*-+=";
93 - my $configdb = esmith::ConfigDB->open();
94 - my $rec = $configdb->get('passwordstrength');
95 - my $check_type = ($rec ? ($rec->prop('Users') || 'none') : 'none');
96
97 - $siz = 7 if( $siz < 7 );
98 - my $valid = '';
99 - my $fm = new esmith::FormMagick();
100 - my $pass;
101 - while( $valid ne 'OK' ) {
102 - $pass = generate_password( $siz, $addConsonants, 'yes', $mixedCase, 10, $symbols );
103 - $valid=validate_password($fm, $check_type,$pass);
104 - #print "$pass (invalid)\n" if( $invalid);
105 - }
106 -
107 - return $pass;
108 - }
109 -
110 -sub generate_password( $$$$$$ )
111 -{
112 - my ( $siz, $addConsonants, $firstUpper, $mixedCase, $symbolOdds, $symbols ) = @_;
113 - # USER CHANGEABLE CONSTANTS FOLLOW
114 -
115 - # Increase the default 8 to change the generated password size
116 - # and extra letters will be added to the end. Decrease and
117 - # you'll lose some or all of the second string of letters.
118 - # Depending on the value of $addConsonants the actual
119 - # password length may range from $siz to $siz + 2.
120 - # Size interacts with other choices. If $addConsonants is false
121 - # size will be fixed length and is achieved by truncation after
122 - # checking for upper case and digits so short sizes (3 - 5) may
123 - # not have the variability you desire.
124 - $siz = 8 unless $siz;
125 - # A $siz less than 3 creates an endless loop.
126 - $siz = 3 if ($siz < 3);
127 -
128 - # Change $addConsonats to 0 to prevent some extra consonants
129 - # from being tacked on to letter sequences. Leave $addConsonants
130 - # at 1 to sometimes add an extra consonant to letter sequences.
131 - # If left at 1 the password size will vary from $siz to $siz+2.
132 - $addConsonants = lc($addConsonants) eq "yes" ? 1 : 0;
133 - # Change $firstUpper to 0 to prevent the first character of each
134 - # letter sequence from being upper case. Leave it as 1 if you
135 - # want some of the first characters to be upper case.
136 - $firstUpper = lc($firstUpper) eq "yes" ? 1 : 0;
137 -
138 - # Change $mixedCase to 1 to mix the case of all letters.
139 - # $mixedCase is not random as subsequent checks force at
140 - # least one upper and one lower case letter in each password.
141 - # Leave it at 0 so all letters will be lower case or only
142 - # the first or each letter sequence may be upper case.
143 - $mixedCase = lc($mixedCase) eq "yes" ? 1 : 0;
144 -
145 - # By changing $symbolOdds from 0 to 10 you change the likelihood
146 - # of having two numbers or a number and a symbol. At 0 you will
147 - # always get 2 digits. At 1 you will usually only get one digit
148 - # but will sometimes get a second digit or a symbol. At 10 you
149 - # will always get two numbers or a number and a symbol with the
150 - # about even chances that one of the two characters will be a
151 - # symbol. The odds are affected by what characters are added to
152 - # or removed from the $sym initialization string.
153 - # The default is 7.
154 - $symbolOdds = 7 unless ($symbolOdds >= 0 and $symbolOdds <= 10);
155 -
156 - # Add or remove symbols to make passwords easier or harder
157 - # to type. Delete the second set of digits to increase
158 - # the relative frequency of symbols and punctuation.
159 - # Add some vowels or consonants to really change the patterns
160 - # but these will also get much harder to remember.
161 - # The $ needs to be escaped if it is to be available as a
162 - # password character.
163 - my $sym = $symbols ? $symbols : ",.<>~`!@#\$%^&*()-_+=";
164 - my $numb = "5678123490";
165 - while( length($numb) < length($sym) ) {
166 - $numb .= int(rand(10));
167 - }
168 - my $lsym = length($sym);
169 - while( length($numb) > length($sym) ) {
170 - $sym .= substr($sym,int(rand($lsym)),1)
171 - }
172 - $numb .= $sym;
173 - my $lnumb = length($numb);
174 -
175 - # USER CHANGEABLE CONSTANTS END - Changing the constants as
176 - # specified above has been fairly well tested. Any changes
177 - # below here and you are changing the logic of the program.
178 - # You should be familiar with programming if you make changes
179 - # after this point.
180 -
181 - # Unless you plan to change the logic in the loop below,
182 - # leave this next alone and control case with $firstUpper and
183 - # $mixedCase above. $mixedCase supercedes if both are true.
184 - my $upr = "BbCcDdFfGgHhJjKkLlMNPXYZmnpqrstvQRSTVWwxyz";
185 - my $cons = "bcdrstvwxyzfghjklmnpq";
186 - my $vowel;
187 - if ($mixedCase) {
188 - $vowel = "aAeEiIoOuU";
189 - $cons = $upr;
190 - } else {
191 - $vowel = "uoiea";
192 - }
193 - $upr = $cons unless ($firstUpper);
194 - my $lvowel = length($vowel);
195 - my $lcons = length($cons);
196 - my $lupr = length($upr);
197 -
198 - my $realSize = $siz;
199 - $realSize += 2 if ($addConsonants);
200 - my $linelen = 0;
201 -
202 - my $skipThisOne=1;
203 - while ($skipThisOne) {
204 - # Plan to use this password unless . . .
205 - $skipThisOne = 0;
206 - my $pass = "";
207 - my $k = 0;
208 - for (my $i=0; $i<$siz; $i++) {
209 - # The basic password structure is cvc99cvc. Depending on
210 - # how $cons and $upr have been initialized above case will
211 - # be all lower, first upper or random.
212 - if ($i==0 or $i==2 or $i==5 or $i==7) {
213 - if ($i==0 or $i==5) {
214 - $pass .= substr($upr,int(rand($lupr)),1);
215 - } else {
216 - $pass .= substr($cons,int(rand($lcons)),1);
217 - }
218 - # The next will conditionally add up to 2 consonants
219 - # pseudo randomly after the four "standard" consonants.
220 - if ($addConsonants and (int(rand(4)) == 3) and $k < 2) {
221 - $pass .= substr($cons,int(rand($lcons)),1);
222 - $k++;
223 - }
224 - }
225 -
226 - # Pad the password with letters if $siz is over 7.
227 - if ($i > 7) {
228 - if (int(rand(26)) <= 5) {
229 - $pass .= substr($vowel,int(rand($lvowel)),1);
230 - } else {
231 - $pass .= substr($cons,int(rand($lcons)),1);
232 - }
233 - }
234 -
235 - # Put the vowels in cvc99cvc. Case depends on how $vowel
236 - # was initialized above.
237 - $pass .= substr($vowel,int(rand($lvowel)),1)
238 - if ($i==1 or $i==6);
239 -
240 - # Change $symbolOdds initialization above to affect the
241 - # number of numbers and symbols and their ratio.
242 - if ($i==3 or $i==4) {
243 - # If $symbolOdds is non zero take any character
244 - # from the $numb string which has digits, symbols
245 - # and punctuation.
246 - if ($symbolOdds) {
247 - $pass .= substr($numb,int(rand($lnumb)),1)
248 - if (int(rand(10)) <= $symbolOdds);
249 - } else {
250 - # If $symbolOdds is zero keep trying until a
251 - # a digit is found.
252 - my $n = "";
253 - until ($n =~ /[0-9]/) {
254 - $n = substr($numb,int(rand($lnumb)),1);
255 - }
256 - $pass .= $n;
257 - }
258 - }
259 - }
260 -
261 - # Check the password length.
262 - $pass = substr($pass,0,$realSize) if (length($pass) > $realSize);
263 -
264 - # Include at least one digit.
265 - $skipThisOne = 1 unless ($pass =~ /[0-9]/);
266 - # Include at least one lower case letter.
267 - $skipThisOne = 1 unless ($pass =~ /[a-z]/);
268 - # Conditionally insure that first character is upper case.
269 - $skipThisOne = 1
270 - if (!($pass =~ /[^a-zA-z][A-Z]/) and $firstUpper );
271 - $skipThisOne = 1
272 - if (!($pass =~ /^[A-Z]/) and $firstUpper );
273 - # Conditionally insure at least one upper case character.
274 - $skipThisOne = 1
275 - if (!($pass =~ /[A-Z]/) and $mixedCase);
276 - # If any test fails get another password.
277 - if ($skipThisOne) {
278 - next;
279 - }
280 -
281 - return $pass;
282 - }
283 -}
284 -
285 -# main
286 for(my $i=0; $i<($opts{'number'}?$opts{'number'}:1); $i++)
287 {
288 my $pw=sme_generate_password(
289 @@ -295,4 +33,3 @@
290 );
291 print "$pw\n";
292 }
293 -

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed