diff --git a/curl-authchecker.md b/curl-authchecker.md new file mode 100644 index 0000000..026d027 --- /dev/null +++ b/curl-authchecker.md @@ -0,0 +1,72 @@ +## curl keeps asking for password until correct, and downloads file + +``` +function getcurlsec { + +local curlurl="$1" +local curluser="$2" +local curloutput="$3" + +while true; do + curl --fail --user "$curluser" "$curlurl" -o "$curloutput" + local EC=$? + if [ $EC -eq 0 ]; then + break + fi +done + +} +``` + +Syntax: `getcurlsec ` + + +## curl downloads file using given credentials + +``` +function getcurlsecwpassword { + +local curlurl="$1" +local curluser="$2" +local curlpassword="$3" +local curloutput="$4" + curl --fail --user "$curluser":"curlpassword" "$curlurl" -o "$curloutput" + local EC=$? + if [ $EC -eq 0 ]; then + echo "Password correct" + else + echo "Password incorrect" + fi +} +``` + +Syntax: `getcurlsecwpassword ` + + +## curl keeps asking for password until correct, and stores username and password as var + +``` +function checkusercurl { + +local curlurl="$1" +curluser="$2" + +while true; do + read -s -p "Enter password for user $curluser: " curlpassword + echo ""; + curl -s --fail --user "$curluser":"$curlpassword" "$curlurl" -o /dev/null + local EC=$? + if [ $EC -eq 0 ]; then + echo "Password correct" + break + fi + echo "Incorrect password" + unset curlpassword +done + +} +``` + +Syntax: `checkusercurl ` +username wil become var: curluser +password wil become var: $curlpassword \ No newline at end of file