Skip to content

Commit e05fd26

Browse files
Ahamed-AliPureWeen
authored andcommitted
[Windows] Fixed the Pasted Password Becomes Visible When IsPassword Is Enabled (#30353)
* Fixed the masked text issue of same value pasted into the textbox field * Added the test for verifying the masked text
1 parent 18f7dd5 commit e05fd26

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Windows.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,41 @@ public async Task EntryAlignmentMatchesFlowDirection(bool isExplicit, FlowDirect
7676

7777
Assert.Equal(expectedAlignment, nativeAlignment);
7878
}
79+
80+
[Fact]
81+
[Description("Password entry should refresh obfuscation when identical text is pasted")]
82+
public async Task PasswordEntryObfuscatesIdenticalPastedText()
83+
{
84+
var entry = new Entry
85+
{
86+
Text = "password123",
87+
IsPassword = true
88+
};
89+
90+
await InvokeOnMainThreadAsync(() =>
91+
{
92+
var handler = CreateHandler<EntryHandler>(entry);
93+
var platformControl = GetPlatformControl(handler);
94+
var passwordTextBox = platformControl as Microsoft.Maui.Platform.MauiPasswordTextBox;
95+
96+
Assert.NotNull(passwordTextBox);
97+
Assert.True(passwordTextBox.IsPassword);
98+
99+
// Verify the text is initially obfuscated
100+
Assert.Equal(new string('●', entry.Text.Length), passwordTextBox.Text);
101+
102+
// Simulate pasting the same text by setting the same text value
103+
passwordTextBox.Text = "password123";
104+
105+
// This is equivalent to what happens when a user pastes identical text via Ctrl+V
106+
passwordTextBox.GetType().GetMethod("UpdatePasswordIfNeeded",
107+
System.Reflection.BindingFlags.NonPublic |
108+
System.Reflection.BindingFlags.Instance)?.Invoke(passwordTextBox, null);
109+
110+
111+
// Verify the text is still properly obfuscated after the "paste" operation
112+
Assert.Equal(new string('●', entry.Text.Length), passwordTextBox.Text);
113+
});
114+
}
79115
}
80116
}

src/Core/src/Platform/Windows/MauiPasswordTextBox.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,15 @@ void UpdatePasswordIfNeeded()
298298
var updatedPassword = DetermineTextFromPassword(Password, SelectionStart, Text);
299299

300300
if (Password != updatedPassword)
301+
{
301302
Password = updatedPassword;
303+
}
304+
else
305+
{
306+
// Ensure the UI properly refreshes when text is pasted with the same value
307+
// Without this, pasting identical text via Ctrl+V doesn't trigger obfuscation
308+
UpdateVisibleText();
309+
}
302310
}
303311

304312
static string Obfuscate(string text, bool leaveLastVisible = false)

0 commit comments

Comments
 (0)