@@ -97,9 +97,9 @@ Result:
97
97
"challenge" : " a2926b025bcc8618c632f81cd6cf7c37ee051c08aab74b565fd5126350fcd056" ,
98
98
"session" :
99
99
{
100
- "valid" : false ,
101
- "sid" : null ,
102
- "validity" : null
100
+ "valid" : false ,
101
+ "sid" : null ,
102
+ "validity" : null
103
103
}
104
104
}
105
105
```
@@ -111,7 +111,7 @@ Below, we provide concrete examples of how to authenticate with the Pi-hole API.
111
111
112
112
### Bash
113
113
114
- ``` bash
114
+ ``` bash linenums="1"
115
115
computePWhash () {
116
116
local password hash1 hash2
117
117
password=" ${1} "
@@ -129,7 +129,7 @@ computeResponse() {
129
129
}
130
130
```
131
131
132
- ``` bash
132
+ ``` bash linenums="1" hl_lines="4 5 6"
133
133
password=" ABC"
134
134
pwhash=" $( computePWhash " $password " ) "
135
135
@@ -145,7 +145,7 @@ sid="$(jq --raw-output .session.sid <<< "${session}")"
145
145
146
146
We recommend using [ ` geraintluff/sha256 ` ] ( https://github.com/geraintluff/sha256 ) providing a small (less than 1 KB) SHA-256 implementation.
147
147
148
- ``` javascript
148
+ ``` javascript linenums="1" hl_lines="4 8 16"
149
149
function getPWhash (password ) {
150
150
// Compute password hash twice to mitigate rainbow
151
151
// table vulnerability
@@ -180,22 +180,25 @@ function doLogin(pwhash) {
180
180
}
181
181
});
182
182
}
183
+ ```
183
184
185
+ ``` javascript linenums="1"
184
186
var password = " ABC" ;
185
187
var pwhash = getPWhash (" ABC" );
186
188
doLogin (pwhash);
187
189
```
188
190
189
191
### Python 3
190
192
191
- ``` python
193
+ ``` python linenums="1" hl_lines="10 11 12"
192
194
import requests
193
195
from hashlib import sha256
194
196
195
197
url = " http://pi.hole/api/auth"
196
198
197
199
password = b " ABC"
198
- pwhash = sha256(sha256(password).hexdigest().encode(" ascii" )).hexdigest().encode(" ascii" )
200
+ pwhash_ = sha256(password).hexdigest().encode(" ascii" )
201
+ pwhash = sha256(pwhash_).hexdigest().encode(" ascii" )
199
202
200
203
challenge = requests.get(url).json()[" challenge" ].encode(' ascii' )
201
204
response = sha256(challenge + b " :" + pwhash).hexdigest().encode(" ascii" )
@@ -213,9 +216,9 @@ The result of a successful authentication is
213
216
{
214
217
"session" :
215
218
{
216
- "valid" : true ,
217
- "sid" : " XwrWDU7EDg64dX0sxmURDA==" ,
218
- "validity" : 300
219
+ "valid" : true ,
220
+ "sid" : " XwrWDU7EDg64dX0sxmURDA==" ,
221
+ "validity" : 300
219
222
}
220
223
}
221
224
```
0 commit comments