Browse code

Allow only aphanum chars in user-entered passwords

Fixes bug 885345

Change-Id: Ib41319676d2fd24144a1493bd58543ad71eb8d6c

Dean Troyer authored on 2011/12/30 08:27:45
Showing 1 changed files
... ...
@@ -244,12 +244,17 @@ function read_password {
244 244
         echo '################################################################################'
245 245
         echo $msg
246 246
         echo '################################################################################'
247
-        echo "This value will be written to your localrc file so you don't have to enter it again."
248
-        echo "It is probably best to avoid spaces and weird characters."
247
+        echo "This value will be written to your localrc file so you don't have to enter it "
248
+        echo "again.  Use only alphanumeric characters."
249 249
         echo "If you leave this blank, a random default value will be used."
250
-        echo "Enter a password now:"
251
-        read -e $var
252
-        pw=${!var}
250
+        pw=" "
251
+        while true; do
252
+            echo "Enter a password now:"
253
+            read -e $var
254
+            pw=${!var}
255
+            [[ "$pw" = "`echo $pw | tr -cd [:alnum:]`" ]] && break
256
+            echo "Invalid chars in password.  Try again:"
257
+        done
253 258
         if [ ! $pw ]; then
254 259
             pw=`openssl rand -hex 10`
255 260
         fi