Reset password
curl --request POST \
--url https://api.example.com/api/v1/auth/reset-passwordimport requests
url = "https://api.example.com/api/v1/auth/reset-password"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/api/v1/auth/reset-password', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/auth/reset-password",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/auth/reset-password"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/auth/reset-password")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/auth/reset-password")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyAuth
Reset password
Confirm a 6-digit reset code and set a new password.
POST
/
api
/
v1
/
auth
/
reset-password
Reset password
curl --request POST \
--url https://api.example.com/api/v1/auth/reset-passwordimport requests
url = "https://api.example.com/api/v1/auth/reset-password"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/api/v1/auth/reset-password', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/auth/reset-password",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/auth/reset-password"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/auth/reset-password")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/auth/reset-password")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyOverview
Confirms a password reset by submitting the 6-digit code received viaPOST /forgot-password along with the new password.
On success:
- The OTP row is marked consumed.
- The new password is hashed with argon2id and persisted.
- All active refresh tokens for the user are revoked — every device gets logged out. This is intentional: if the reset request was attacker-driven, the legitimate user still controls their email, but we cannot trust any session that might predate the request.
POST /login with the new password to start a fresh session.
Same 5-attempt cap and INVALID_CODE / CODE_EXPIRED semantics as /verify-email.
Authentication
None required.Path parameters
None.Query parameters
None.Request body
| Field | Type | Required | Allowed values | Example |
|---|---|---|---|---|
email | string | yes | RFC 5322 valid, lowercased server-side | alice@example.com |
code | string | yes | Exactly 6 digits | 729048 |
newPassword | string | yes | 8..200 chars; must contain at least one letter AND one digit | n3wsecret9 |
Example payload
{
"email": "alice@example.com",
"code": "729048",
"newPassword": "n3wsecret9"
}
Response — 200 OK
| Field | Type | Notes | Example |
|---|---|---|---|
ok | boolean | Always true on success. Client should now call /auth/login with the new password. | true |
Example response
{
"ok": true
}
Error responses
| Status | Code | Meaning |
|---|---|---|
| 400 | VALIDATION_FAILED | Email malformed, code not 6 digits, or new password fails the policy. |
| 401 | INVALID_CODE | Wrong digits; attemptsUsed bumped. After 5 tries the row dies. |
| 401 | CODE_EXPIRED | No live reset OTP — either it expired (15-min TTL), was already consumed, or the attempt cap was hit. Restart from /forgot-password. |
Example error — 401 INVALID_CODE
{
"type": "https://api.swappr.co.uk/errors/invalid-code",
"title": "Verification code incorrect",
"status": 401,
"code": "INVALID_CODE",
"detail": "Reset code is incorrect",
"instance": "/api/v1/auth/reset-password",
"requestId": "01HZQ7K3M4N5P6Q7R8S9T0V1W2"
}
Side effects
- Consumes the
otp_codesrow. - Updates
users.passwordHashto the new argon2id hash. - Updates all matching
refresh_tokensrows torevokedAt = now— every active session is killed. - Sets
users.emailVerified = trueif it was not already — the reset code proves control of the inbox, so the new password is not stopped by login’sEMAIL_NOT_VERIFIEDgate.
See also
- Forgot password — get the reset code.
- Login — log in with the new password.
curl
curl -X POST https://api.swappr.co.uk/api/v1/auth/reset-password \
-H "Content-Type: application/json" \
-d '{
"email": "alice@example.com",
"code": "729048",
"newPassword": "n3wsecret9"
}'