Archived
1
0
This repository has been archived on 2023-11-17. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
linux/curl-authchecker.md

72 lines
1.4 KiB
Markdown

## 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 <url to download> <username> <output file>`
## 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 <url to download> <username> <password> <output file>`
## 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 <url to authenticate against> <username>`
username wil become var: curluser
password wil become var: $curlpassword