Browse Source

Merge pull request #4 from vestacp-user/release_gen_pass

Release gen pass
vestacp-user 5 years ago
parent
commit
f08bf3931c
3 changed files with 7 additions and 24 deletions
  1. 5 10
      func/main.sh
  2. 1 7
      test/test.bats
  3. 1 7
      test/test_actions.sh

+ 5 - 10
func/main.sh

@@ -165,19 +165,14 @@ get_user_owner() {
 # Random password generator
 generate_password() {
     matrix=$1
-    lenght=$2
+    length=$2
     if [ -z "$matrix" ]; then
-        matrix=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
+        matrix=[:alnum:]
     fi
-    if [ -z "$lenght" ]; then
-        lenght=10
+    if [ -z "$length" ]; then
+        length=10
     fi
-    i=1
-    while [ $i -le $lenght ]; do
-        pass="$pass${matrix:$(($RANDOM%${#matrix})):1}"
-       ((i++))
-    done
-    echo "$pass"
+    cat /dev/urandom | tr -dc $matrix | head -c$length
 }
 
 # Package existence check

+ 1 - 7
test/test.bats

@@ -6,13 +6,7 @@ load 'test_helper/bats-file/load'
 
 
 function random() {
-    MATRIX='0123456789'
-    LENGTH=$1
-    while [ ${n:=1} -le $LENGTH ]; do
-        rand="$rand${MATRIX:$(($RANDOM%${#MATRIX})):1}"
-        let n+=1
-    done
-    echo "$rand"
+    cat /dev/urandom | tr -dc [:digit:] | head -c$1
 }
 
 function setup() {

+ 1 - 7
test/test_actions.sh

@@ -7,13 +7,7 @@ V_TEST="$HESTIA/test"
 
 # Define functions
 random() {
-    MATRIX='0123456789'
-    LENGTH=$1
-    while [ ${n:=1} -le $LENGTH ]; do
-        rand="$rand${MATRIX:$(($RANDOM%${#MATRIX})):1}"
-        let n+=1
-    done
-    echo "$rand"
+    cat /dev/urandom | tr -dc [:digit:] | head -c$1
 }
 
 echo_result() {