From 7466b5727ae6f523bc199a77d2df85e0b959fee0 Mon Sep 17 00:00:00 2001 From: Bram Prieshof Date: Fri, 16 Oct 2020 00:57:06 +0000 Subject: [PATCH] 'curl-authchecker.md' toevoegen --- curl-authchecker.md | 72 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 curl-authchecker.md 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