mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 11:28:14 +00:00
Display the number of PIN entry attempts remaining.
This commit is contained in:
parent
9f75d342a4
commit
3517018f30
@ -11,7 +11,7 @@ class PinCancelled(Exception):
|
||||
|
||||
|
||||
@ui.layout
|
||||
async def request_pin(label=None, cancellable: bool = True) -> str:
|
||||
async def request_pin(label=None, attempts_remaining=None, cancellable: bool = True) -> str:
|
||||
def onchange():
|
||||
c = dialog.cancel
|
||||
if matrix.pin:
|
||||
@ -36,7 +36,13 @@ async def request_pin(label=None, cancellable: bool = True) -> str:
|
||||
|
||||
if label is None:
|
||||
label = "Enter your PIN"
|
||||
matrix = PinMatrix(label)
|
||||
sublabel = None
|
||||
if attempts_remaining:
|
||||
if attempts_remaining == 1:
|
||||
sublabel = "This is your last attempt"
|
||||
else:
|
||||
sublabel = "{} attempts remaining".format(attempts_remaining)
|
||||
matrix = PinMatrix(label, sublabel)
|
||||
matrix.onchange = onchange
|
||||
dialog = ConfirmDialog(matrix)
|
||||
dialog.cancel.area = ui.grid(12)
|
||||
|
@ -34,11 +34,11 @@ def _new_device_id() -> str:
|
||||
|
||||
|
||||
def get_device_id() -> str:
|
||||
dev_id = config.get(_APP, _DEVICE_ID, True).decode() # public
|
||||
dev_id = config.get(_APP, _DEVICE_ID, True) # public
|
||||
if not dev_id:
|
||||
dev_id = _new_device_id()
|
||||
config.set(_APP, _DEVICE_ID, dev_id.encode(), True) # public
|
||||
return dev_id
|
||||
dev_id = _new_device_id().encode()
|
||||
config.set(_APP, _DEVICE_ID, dev_id, True) # public
|
||||
return dev_id.decode()
|
||||
|
||||
|
||||
def is_initialized() -> bool:
|
||||
|
@ -16,7 +16,7 @@ async def change_pin(ctx, msg):
|
||||
|
||||
# get current pin, return failure if invalid
|
||||
if config.has_pin():
|
||||
curpin = await request_pin_ack(ctx)
|
||||
curpin = await request_pin_ack(ctx, "Enter old PIN", config.get_pin_rem())
|
||||
if not config.check_pin(pin_to_int(curpin)):
|
||||
raise wire.PinInvalid("PIN invalid")
|
||||
else:
|
||||
|
@ -13,7 +13,7 @@ async def bootscreen():
|
||||
await lockscreen()
|
||||
label = None
|
||||
while True:
|
||||
pin = await request_pin(label)
|
||||
pin = await request_pin(label, config.get_pin_rem())
|
||||
if config.unlock(pin_to_int(pin)):
|
||||
return
|
||||
else:
|
||||
|
@ -19,8 +19,9 @@ def generate_digits():
|
||||
|
||||
|
||||
class PinMatrix(ui.Widget):
|
||||
def __init__(self, label, pin="", maxlength=9):
|
||||
def __init__(self, label, sublabel, pin="", maxlength=9):
|
||||
self.label = label
|
||||
self.sublabel = sublabel
|
||||
self.pin = pin
|
||||
self.maxlength = maxlength
|
||||
self.digits = generate_digits()
|
||||
@ -48,7 +49,7 @@ class PinMatrix(ui.Widget):
|
||||
return
|
||||
|
||||
# clear canvas under input line
|
||||
display.bar(0, 0, ui.WIDTH, 45, ui.BG)
|
||||
display.bar(0, 0, ui.WIDTH, 52, ui.BG)
|
||||
|
||||
if self.pin:
|
||||
# input line with pin
|
||||
@ -60,6 +61,10 @@ class PinMatrix(ui.Widget):
|
||||
x = (box_w - l * padding) // 2
|
||||
for i in range(0, l):
|
||||
ui.display.bar_radius(x + i * padding, y, size, size, ui.GREY, ui.BG, 4)
|
||||
elif self.sublabel:
|
||||
# input line with header label and sublabel
|
||||
display.text_center(ui.WIDTH // 2, 20, self.label, ui.BOLD, ui.GREY, ui.BG)
|
||||
display.text_center(ui.WIDTH // 2, 46, self.sublabel, ui.NORMAL, ui.GREY, ui.BG)
|
||||
else:
|
||||
# input line with header label
|
||||
display.text_center(ui.WIDTH // 2, 36, self.label, ui.BOLD, ui.GREY, ui.BG)
|
||||
|
Loading…
Reference in New Issue
Block a user