Skip to content

Commit b7d4b6c

Browse files
committed
refactor: handle censored password in the auth module
1 parent 7d46967 commit b7d4b6c

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/auth.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use ratatui::{
44
style::{Color, Style, Stylize},
55
widgets::{Block, BorderType, Borders, Clear, Padding, Paragraph},
66
};
7+
use tui_input::Input;
78

89
pub struct Auth;
910

1011
impl Auth {
11-
pub fn render(&self, frame: &mut Frame, passkey: &str) {
12+
pub fn render(&self, frame: &mut Frame, input: &Input, show_password: bool) {
1213
let popup_layout = Layout::default()
1314
.direction(Direction::Vertical)
1415
.constraints([
@@ -66,10 +67,16 @@ impl Auth {
6667
.style(Style::default().fg(Color::White))
6768
.block(Block::new().padding(Padding::uniform(1)));
6869

69-
let passkey = Paragraph::new(passkey)
70-
.alignment(Alignment::Center)
71-
.style(Style::default().fg(Color::White))
72-
.block(Block::new().style(Style::default().bg(Color::DarkGray)));
70+
let passkey = Paragraph::new({
71+
if show_password {
72+
input.value().to_string()
73+
} else {
74+
"*".repeat(input.value().len())
75+
}
76+
})
77+
.alignment(Alignment::Center)
78+
.style(Style::default().fg(Color::White))
79+
.block(Block::new().style(Style::default().bg(Color::DarkGray)));
7380

7481
frame.render_widget(Clear, area);
7582

src/ui.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ pub fn render(app: &mut App, frame: &mut Frame) {
2121
// Auth Popup
2222
if app.authentication_required.load(Ordering::Relaxed) {
2323
app.focused_block = FocusedBlock::AuthKey;
24-
let censored_password = "*".repeat(app.passkey_input.value().len());
25-
if app.show_password {
26-
Auth.render(frame, app.passkey_input.value());
27-
} else {
28-
Auth.render(frame, &censored_password);
29-
}
24+
Auth.render(frame, &app.passkey_input, app.show_password);
3025
}
3126

3227
// Access Point Popup

0 commit comments

Comments
 (0)