Skip to content

Commit

Permalink
show remaining attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarprudnikov committed Apr 22, 2024
1 parent 0a6be01 commit 91820aa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions internal/storage/memstore/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ func (s *memMessageStore) GetFullMessage(id string, pin string) (*storage.Messag
return &msg, nil
}

msg.Attempt += 1
msg.AttemptsRemaining -= 1
s.messages.Store(id, msg)

// If the pin was wrong then start tracking attempts
if msg.Attempt >= storage.MAX_PIN_ATTEMPTS {
if msg.AttemptsRemaining <= 0 {
s.messages.Delete(id)
}
} else {
Expand Down
12 changes: 6 additions & 6 deletions internal/storage/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type MessageStore interface {

type Message struct {
aztables.Entity
Content string `json:"content,omitempty"`
Pin string `json:"pin,omitempty"`
Attempt int `json:"Attempt,omitempty"`
Content string `json:"content,omitempty"`
Pin string `json:"pin,omitempty"`
AttemptsRemaining int `json:"remaining,omitempty"`
}

func NewMessage(username string, ciphertext string, pin string) (Message, error) {
Expand All @@ -36,8 +36,8 @@ func NewMessage(username string, ciphertext string, pin string) (Message, error)
RowKey: username,
Timestamp: aztables.EDMDateTime(t),
},
Content: ciphertext,
Pin: pinHash,
Attempt: 0,
Content: ciphertext,
Pin: pinHash,
AttemptsRemaining: MAX_PIN_ATTEMPTS,
}, nil
}
3 changes: 3 additions & 0 deletions web/message.show.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<input type="password" name="pin" class="form-control" aria-describedby="pinHelp" id="pin" placeholder="secret PIN" />
<div id="pinHelp" class="form-text">Provide a PIN to unlock content</div>
</div>
<div class="mb-3">
<div class="form-text">Remaining attempts: {{ .data.AttemptsRemaining }}</div>
</div>
<button type="submit" class="btn btn-primary">Validate and decrypt</button>
</form>
{{end}}
Expand Down

0 comments on commit 91820aa

Please sign in to comment.