Skip to content

Commit 3a3d6d5

Browse files
committed
Use Bluesky PDS email code format
1 parent 38c6d71 commit 3a3d6d5

File tree

9 files changed

+24
-37
lines changed

9 files changed

+24
-37
lines changed

frontend/src/templates/AccountPage.mlx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ let[@react.component] make
252252
<Input
253253
name="token"
254254
label="Verification code"
255-
placeholder="eml-..."
255+
placeholder="A1B2C-3D4E5"
256256
required=true
257257
showIndicator=false
258258
value=emailTokenInput
@@ -416,7 +416,7 @@ let[@react.component] make
416416
<Input
417417
name="email_token"
418418
label="Confirmation code"
419-
placeholder="eml-..."
419+
placeholder="A1B2C-3D4E5"
420420
showIndicator=false
421421
value=confirmEmailTokenInput
422422
onChange=(fun e ->

pegasus/lib/api/account_/index.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ let has_valid_delete_code (actor : Data_store.Types.actor) =
77

88
let has_valid_email_change_code (actor : Data_store.Types.actor) =
99
match (actor.auth_code, actor.auth_code_expires_at, actor.pending_email) with
10-
| Some code, Some expires_at, Some _ ->
11-
String.starts_with ~prefix:"eml-" code && expires_at > Util.now_ms ()
10+
| Some _, Some expires_at, Some _ ->
11+
expires_at > Util.now_ms ()
1212
| _ ->
1313
false
1414

1515
let has_valid_email_confirmation_code (actor : Data_store.Types.actor) =
1616
match (actor.auth_code, actor.auth_code_expires_at, actor.pending_email) with
17-
| Some code, Some expires_at, None ->
18-
String.starts_with ~prefix:"eml-" code && expires_at > Util.now_ms ()
17+
| Some _, Some expires_at, None ->
18+
expires_at > Util.now_ms ()
1919
| _ ->
2020
false
2121

pegasus/lib/api/identity/requestPlcOperationSignature.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
let handler =
22
Xrpc.handler ~auth:Authorization (fun {auth; db; _} ->
33
let did = Auth.get_authed_did_exn auth in
4-
let code =
5-
"plc-"
6-
^ String.sub
7-
Digestif.SHA256.(
8-
digest_string (did ^ Int.to_string @@ Util.now_ms ()) |> to_hex )
9-
0 8
10-
in
4+
let code = Util.make_code () in
115
let expires_at = Util.now_ms () + (60 * 60 * 1000) in
126
let%lwt () = Data_store.set_auth_code ~did ~code ~expires_at db in
137
let%lwt {email; handle; _} =

pegasus/lib/api/identity/signPlcOperation.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ let handler =
2222
| Some actor -> (
2323
match (actor.auth_code, actor.auth_code_expires_at) with
2424
| Some auth_code, Some auth_expires_at
25-
when String.starts_with ~prefix:"plc-" auth_code
26-
&& input.token = auth_code
27-
&& Util.now_ms () < auth_expires_at -> (
25+
when input.token = auth_code && Util.now_ms () < auth_expires_at -> (
2826
match%lwt Plc.get_audit_log did with
2927
| Ok log ->
3028
let latest = Mist.Util.last log |> Option.get in

pegasus/lib/api/server/confirmEmail.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ let confirm_email ~email ~token (actor : Data_store.Types.actor) db =
1010
else
1111
match (actor.auth_code, actor.auth_code_expires_at) with
1212
| Some auth_code, Some expires_at
13-
when String.starts_with ~prefix:"eml-" auth_code
14-
&& auth_code = token
15-
&& Util.now_ms () < expires_at ->
13+
when auth_code = token && Util.now_ms () < expires_at ->
1614
let%lwt () = Data_store.confirm_email ~did:actor.did db in
1715
Lwt.return_ok ()
1816
| Some _, Some expires_at when Util.now_ms () >= expires_at ->

pegasus/lib/api/server/requestEmailConfirmation.ml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@ let request_email_confirmation (actor : Data_store.Types.actor) db =
55
| Some _ ->
66
Lwt.return_error AlreadyConfirmed
77
| None ->
8-
let code =
9-
"eml-"
10-
^ String.sub
11-
Digestif.SHA256.(
12-
digest_string (actor.did ^ Int.to_string @@ Util.now_ms ())
13-
|> to_hex )
14-
0 8
15-
in
8+
let code = Util.make_code () in
169
let expires_at = Util.now_ms () + (10 * 60 * 1000) in
1710
let%lwt () =
1811
Data_store.set_auth_code ~did:actor.did ~code ~expires_at db

pegasus/lib/api/server/requestEmailUpdate.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ let request_email_update ?pending_email (actor : Data_store.Types.actor) db =
88
let%lwt () =
99
if token_required then
1010
let did = actor.did in
11-
let code =
12-
"eml-"
13-
^ String.sub
14-
Digestif.SHA256.(
15-
digest_string (did ^ Int.to_string @@ Util.now_ms ()) |> to_hex )
16-
0 8
17-
in
11+
let code = Util.make_code () in
1812
let expires_at = Util.now_ms () + (10 * 60 * 1000) in
1913
let%lwt () =
2014
match pending_email with

pegasus/lib/api/server/updateEmail.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ let update_email ?email ~token (actor : Data_store.Types.actor) db =
2929
| Some token -> (
3030
match (actor.auth_code, actor.auth_code_expires_at) with
3131
| Some auth_code, Some expires_at
32-
when String.starts_with ~prefix:"eml-" auth_code
33-
&& auth_code = token
34-
&& Util.now_ms () < expires_at ->
32+
when auth_code = token && Util.now_ms () < expires_at ->
3533
let%lwt () = Data_store.update_email ~did ~email db in
3634
Lwt.return_ok email
3735
| Some _, Some expires_at when Util.now_ms () >= expires_at ->

pegasus/lib/util.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,18 @@ let str_contains ~affix str =
467467
true
468468
with Not_found -> false
469469

470+
let make_code () =
471+
let () = Random.self_init () in
472+
let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" in
473+
let len = String.length chars in
474+
let s = Bytes.create 10 in
475+
for i = 0 to 9 do
476+
let random_index = Random.int len in
477+
Bytes.set s i chars.[random_index]
478+
done ;
479+
let str = Bytes.to_string s in
480+
String.sub str 0 5 ^ "-" ^ String.sub str 5 5
481+
470482
module type Template = sig
471483
type props
472484

0 commit comments

Comments
 (0)