Skip to content

Commit 3514b89

Browse files
committed
Clean up format of 6- vs. 8-digit codes.
1 parent 7cdcf7b commit 3514b89

3 files changed

Lines changed: 25 additions & 27 deletions

File tree

VERSIONS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# PyAuth version history:
22

3-
* 1.1.2 - Rearrange license text display, no functional changes
3+
* 1.2.0
4+
- Rearrange license text display.
5+
- Clean up code display for 6- vs. 8-digit codes.
6+
- Replace the web service call with an internal library for generating QR codes.
47

58
* 1.1.1 - Minor fixes to menus and documentation related to provisioning URIs and QR codes
69

pyauth/AuthEntryPanel.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ def __init__( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.
128128
self.UpdateContents( )
129129

130130
if entry != None:
131-
tmp_code = self.entry.GenerateNextCode( )
132-
self.code = ((8 - len( tmp_code )) * ' ') + tmp_code
131+
self.code = str( self.entry.GenerateNextCode( ) )
133132

134133
self.Bind( wx.EVT_WINDOW_CREATE, self.OnCreate )
135134
self.Bind( wx.EVT_TIMER, self.OnTimerTick )
@@ -240,8 +239,7 @@ def SetEntry( self, entry ):
240239
self.sort_index = entry.GetSortIndex( )
241240
self.code_digits = entry.GetDigits( )
242241
self.SetName( 'entry_panel_{0:d}'.format( self.entry.GetGroup( ) ) )
243-
tmp_code = self.entry.GenerateNextCode( )
244-
self.code = ((8 - len( tmp_code )) * ' ') + tmp_code
242+
self.code = str( self.entry.GenerateNextCode( ) )
245243
## GetLogger().debug( "AEP SE on %s", self.GetName() )
246244
self.ChangeContents( )
247245

@@ -260,10 +258,7 @@ def SetSortIndex( self, index ):
260258
def MaskCode( self, state ):
261259
"""Set the code masking state of the panel."""
262260
self.code_masked = state
263-
if self.code_masked and not self.selected:
264-
self.code_text.SetLabelText( self.code_mask_char * self.code_digits )
265-
else:
266-
self.code_text.SetLabelText( self.code )
261+
self.code_text.SetLabelText( self.GetCodeString( self.selected ) )
267262

268263
def ShowTimer( self, state ):
269264
"""Set the show-timer state of the panel."""
@@ -301,11 +296,7 @@ def UpdateContents( self ):
301296
"""Update the panel's displayed contents based on the current state and entry."""
302297
if self.entry != None:
303298
## GetLogger().debug( "AEP UC updating %s", self.GetName() )
304-
if self.code_masked and not self.selected:
305-
self.code_text.SetLabelText( self.code_mask_char * self.code_digits )
306-
else:
307-
self.code_text.SetLabelText( self.code )
308-
299+
self.code_text.SetLabelText( self.GetCodeString( self.selected ) )
309300
self.provider_text.SetLabelText( self.entry.GetProvider( ) )
310301
self.provider_text.Fit( )
311302
self.account_text.SetLabelText( self.entry.GetAccount( ) )
@@ -344,7 +335,7 @@ def Select( self ):
344335
item.SetBackgroundColour( bg )
345336
item.SetForegroundColour( fg )
346337
# We always show the code when selected regardless of code_masked
347-
self.code_text.SetLabelText( self.code )
338+
self.code_text.SetLabelText( self.GetCodeString( True ) )
348339

349340
def Deselect( self ):
350341
"""Deselect this panel."""
@@ -353,11 +344,7 @@ def Deselect( self ):
353344
self.code_text, self.timer_gauge ]:
354345
item.SetBackgroundColour( wx.NullColour )
355346
item.SetForegroundColour( wx.NullColour )
356-
# We can't be selected, so only code_masked matters
357-
if self.code_masked:
358-
self.code_text.SetLabelText( self.code_mask_char * self.code_digits )
359-
else:
360-
self.code_text.SetLabelText( self.code )
347+
self.code_text.SetLabelText( self.GetCodeString( False ) )
361348

362349
def UpdateTimerGauge( self ):
363350
"""Update the countdown bar and code based on the current time and cycle."""
@@ -367,12 +354,8 @@ def UpdateTimerGauge( self ):
367354
self.totp_cycle = current_time % self.totp_period
368355
# If we wrapped around the end of a cycle, update the code and reset the countdown timer gauge
369356
if self.totp_cycle < last_cycle and self.entry != None:
370-
tmp_code = self.entry.GenerateNextCode( )
371-
self.code = ((8 - len( tmp_code )) * ' ') + tmp_code
372-
if self.code_masked and not self.selected:
373-
self.code_text.SetLabelText( self.code_mask_char * self.code_digits )
374-
else:
375-
self.code_text.SetLabelText( self.code )
357+
self.code = str( self.entry.GenerateNextCode( ) )
358+
self.code_text.SetLabelText( self.GetCodeString( self.selected ) )
376359
# Make our timer gauge count down to zero
377360
self.timer_gauge.SetValue( self.totp_period - self.totp_cycle - 1 )
378361

@@ -391,6 +374,18 @@ def CopyCodeToClipboard( self ):
391374
sts = False
392375
return sts
393376

377+
def GetCodeString( self, selected ):
378+
"""Generate a string containing the code or mask characters."""
379+
if self.code_masked and not selected:
380+
s = self.code_mask_char * self.code_digits
381+
else:
382+
s = self.code
383+
if len( s ) < self.code_max_digits:
384+
pad_len = (self.code_max_digits - len( s )) / 2
385+
tail_len = self.code_max_digits - len( s ) - pad_len
386+
s = (' ' * pad_len) + s + (' ' * tail_len)
387+
return s
388+
394389
def GetProvisioningUri( self ):
395390
return self.entry.GetKeyUri( )
396391

pyauth/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
__program_name__ = "PyAuth"
2121

2222
# Version info
23-
__version__ = '1.1.2'
23+
__version__ = '1.2.0'
2424
__version_tag__ = ''
2525
__version_status__ = 'dev'

0 commit comments

Comments
 (0)