Skip to content

Commit f08bf39

Browse files
authored
Merge pull request hestiacp#4 from vestacp-user/release_gen_pass
Release gen pass
2 parents ec28b9c + 7d9280f commit f08bf39

File tree

3 files changed

+7
-24
lines changed

3 files changed

+7
-24
lines changed

func/main.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,14 @@ get_user_owner() {
165165
# Random password generator
166166
generate_password() {
167167
matrix=$1
168-
lenght=$2
168+
length=$2
169169
if [ -z "$matrix" ]; then
170-
matrix=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
170+
matrix=[:alnum:]
171171
fi
172-
if [ -z "$lenght" ]; then
173-
lenght=10
172+
if [ -z "$length" ]; then
173+
length=10
174174
fi
175-
i=1
176-
while [ $i -le $lenght ]; do
177-
pass="$pass${matrix:$(($RANDOM%${#matrix})):1}"
178-
((i++))
179-
done
180-
echo "$pass"
175+
cat /dev/urandom | tr -dc $matrix | head -c$length
181176
}
182177

183178
# Package existence check

test/test.bats

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ load 'test_helper/bats-file/load'
66

77

88
function random() {
9-
MATRIX='0123456789'
10-
LENGTH=$1
11-
while [ ${n:=1} -le $LENGTH ]; do
12-
rand="$rand${MATRIX:$(($RANDOM%${#MATRIX})):1}"
13-
let n+=1
14-
done
15-
echo "$rand"
9+
cat /dev/urandom | tr -dc [:digit:] | head -c$1
1610
}
1711

1812
function setup() {

test/test_actions.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ V_TEST="$HESTIA/test"
77

88
# Define functions
99
random() {
10-
MATRIX='0123456789'
11-
LENGTH=$1
12-
while [ ${n:=1} -le $LENGTH ]; do
13-
rand="$rand${MATRIX:$(($RANDOM%${#MATRIX})):1}"
14-
let n+=1
15-
done
16-
echo "$rand"
10+
cat /dev/urandom | tr -dc [:digit:] | head -c$1
1711
}
1812

1913
echo_result() {

0 commit comments

Comments
 (0)