diff --git a/doc/guide.html b/doc/guide.html
index 0b647aae9..38247d69e 100644
--- a/doc/guide.html
+++ b/doc/guide.html
@@ -351,7 +351,7 @@ GNU Make
Erlang pgsql library. Optional. For PostgreSQL authentication or storage. See section 3.2.3.
PAM library. Optional. For Pluggable Authentication Modules (PAM). See section 3.1.4.
GNU Iconv 1.8 or higher, for the IRC Transport (mod_irc). Optional. Not needed on systems with GNU Libc. See section 3.3.8.
-ImageMagick’s Convert program, and Bash. Optional. For CAPTCHA challenges. See section 3.1.8.
+ImageMagick’s Convert program. Optional. For CAPTCHA challenges. See section 3.1.8.
exmpp 0.9.1 or higher. Optional. For import/export user data with XEP-0227 XML files.
@@ -1243,7 +1243,7 @@ In order to take effect there must be a translation file
Some ejabberd modules can be configured to require a CAPTCHA challenge on certain actions.
If the client does not support CAPTCHA Forms (XEP-0158),
-a web link is provided so the user can fill the challenge in a web browser.
An example Bash script is provided that generates the image
+a web link is provided so the user can fill the challenge in a web browser.
An example script is provided that generates the image
using ImageMagick’s Convert program.
The configurable options are:
-
{captcha_cmd, Path}
-
diff --git a/doc/guide.tex b/doc/guide.tex
index 7e8143a75..32b8f622a 100644
--- a/doc/guide.tex
+++ b/doc/guide.tex
@@ -315,7 +315,7 @@ To compile \ejabberd{} on a `Unix-like' operating system, you need:
\item Erlang pgsql library. Optional. For PostgreSQL authentication or storage. See section \ref{compilepgsql}.
\item PAM library. Optional. For Pluggable Authentication Modules (PAM). See section \ref{pam}.
\item GNU Iconv 1.8 or higher, for the IRC Transport (mod\_irc). Optional. Not needed on systems with GNU Libc. See section \ref{modirc}.
-\item ImageMagick's Convert program, and Bash. Optional. For CAPTCHA challenges. See section \ref{captcha}.
+\item ImageMagick's Convert program. Optional. For CAPTCHA challenges. See section \ref{captcha}.
\item exmpp 0.9.1 or higher. Optional. For import/export user data with \xepref{0227} XML files.
\end{itemize}
@@ -1546,7 +1546,7 @@ Some \ejabberd{} modules can be configured to require a CAPTCHA challenge on cer
If the client does not support CAPTCHA Forms (\xepref{0158}),
a web link is provided so the user can fill the challenge in a web browser.
-An example Bash script is provided that generates the image
+An example script is provided that generates the image
using ImageMagick's Convert program.
The configurable options are:
diff --git a/tools/captcha.sh b/tools/captcha.sh
index d68edfa03..560a048ad 100755
--- a/tools/captcha.sh
+++ b/tools/captcha.sh
@@ -1,35 +1,70 @@
-#!/bin/bash
+#!/bin/sh
INPUT=$1
-WAVE1_AMPLITUDE=$((2 + $RANDOM % 5))
-WAVE1_LENGTH=$((50 + $RANDOM % 25))
-WAVE2_AMPLITUDE=$((2 + $RANDOM % 5))
-WAVE2_LENGTH=$((50 + $RANDOM % 25))
-WAVE3_AMPLITUDE=$((2 + $RANDOM % 5))
-WAVE3_LENGTH=$((50 + $RANDOM % 25))
-W1_LINE_START_Y=$((10 + $RANDOM % 40))
-W1_LINE_STOP_Y=$((10 + $RANDOM % 40))
-W2_LINE_START_Y=$((10 + $RANDOM % 40))
-W2_LINE_STOP_Y=$((10 + $RANDOM % 40))
-W3_LINE_START_Y=$((10 + $RANDOM % 40))
-W3_LINE_STOP_Y=$((10 + $RANDOM % 40))
+if test -n ${BASH_VERSION:-''} ; then
+ get_random ()
+ {
+ R=$RANDOM
+ }
+else
+ for n in `od -A n -t u2 -N 48 /dev/urandom`; do RL="$RL$n "; done
+ get_random ()
+ {
+ R=${RL%% *}
+ RL=${RL#* }
+ }
+fi
-B1_LINE_START_Y=$(($RANDOM % 40))
-B1_LINE_STOP_Y=$(($RANDOM % 40))
-B2_LINE_START_Y=$(($RANDOM % 40))
-B2_LINE_STOP_Y=$(($RANDOM % 40))
-#B3_LINE_START_Y=$(($RANDOM % 40))
-#B3_LINE_STOP_Y=$(($RANDOM % 40))
+get_random
+WAVE1_AMPLITUDE=$((2 + $R % 5))
+get_random
+WAVE1_LENGTH=$((50 + $R % 25))
+get_random
+WAVE2_AMPLITUDE=$((2 + $R % 5))
+get_random
+WAVE2_LENGTH=$((50 + $R % 25))
+get_random
+WAVE3_AMPLITUDE=$((2 + $R % 5))
+get_random
+WAVE3_LENGTH=$((50 + $R % 25))
+get_random
+W1_LINE_START_Y=$((10 + $R % 40))
+get_random
+W1_LINE_STOP_Y=$((10 + $R % 40))
+get_random
+W2_LINE_START_Y=$((10 + $R % 40))
+get_random
+W2_LINE_STOP_Y=$((10 + $R % 40))
+get_random
+W3_LINE_START_Y=$((10 + $R % 40))
+get_random
+W3_LINE_STOP_Y=$((10 + $R % 40))
-B1_LINE_START_X=$(($RANDOM % 20))
-B1_LINE_STOP_X=$((100 + $RANDOM % 40))
-B2_LINE_START_X=$(($RANDOM % 20))
-B2_LINE_STOP_X=$((100 + $RANDOM % 40))
-#B3_LINE_START_X=$(($RANDOM % 20))
-#B3_LINE_STOP_X=$((100 + $RANDOM % 40))
+get_random
+B1_LINE_START_Y=$(($R % 40))
+get_random
+B1_LINE_STOP_Y=$(($R % 40))
+get_random
+B2_LINE_START_Y=$(($R % 40))
+get_random
+B2_LINE_STOP_Y=$(($R % 40))
+#B3_LINE_START_Y=$(($R % 40))
+#B3_LINE_STOP_Y=$(($R % 40))
-ROLL_X=$(($RANDOM % 40))
+get_random
+B1_LINE_START_X=$(($R % 20))
+get_random
+B1_LINE_STOP_X=$((100 + $R % 40))
+get_random
+B2_LINE_START_X=$(($R % 20))
+get_random
+B2_LINE_STOP_X=$((100 + $R % 40))
+#B3_LINE_START_X=$(($R % 20))
+#B3_LINE_STOP_X=$((100 + $R % 40))
+
+get_random
+ROLL_X=$(($R % 40))
convert -size 180x60 xc:none -pointsize 40 \
\( -clone 0 -fill white \