Skip to content

Commit a714049

Browse files
authored
Guard against null passwords 1/2
1 parent 7bdf451 commit a714049

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Wpf.Ui/Controls/PasswordBox/PasswordBox.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public PasswordBox()
7777
/// <summary>
7878
/// Gets or sets the actual password (not asterisks).
7979
/// </summary>
80-
public string Password
80+
public string? Password
8181
{
8282
get => (string)GetValue(PasswordProperty);
8383
set => SetValue(PasswordProperty, value);
@@ -102,7 +102,7 @@ public bool IsPasswordRevealed
102102
}
103103

104104
/// <summary>
105-
/// Gets or sets whether the password reveal button is enabled.
105+
/// Gets or sets a value indicating whether gets or sets whether the password reveal button is enabled.
106106
/// </summary>
107107
public bool RevealButtonEnabled
108108
{
@@ -147,15 +147,15 @@ protected virtual void OnPasswordCharChanged()
147147
return;
148148
}
149149

150-
UpdateWithLock(() => SetCurrentValue(TextProperty, new string(PasswordChar, Password.Length)));
150+
UpdateWithLock(() => SetCurrentValue(TextProperty, new string(PasswordChar, Password?.Length ?? 0)));
151151
}
152152

153153
/// <summary>
154154
/// Called when the <see cref="IsPasswordRevealed"/> property changes.
155155
/// </summary>
156156
protected virtual void OnIsPasswordRevealedChanged()
157157
{
158-
UpdateWithLock(() => SetCurrentValue(TextProperty, IsPasswordRevealed ? Password : new string(PasswordChar, Password.Length)));
158+
UpdateWithLock(() => SetCurrentValue(TextProperty, IsPasswordRevealed ? Password : new string(PasswordChar, Password?.Length ?? 0)));
159159
}
160160

161161
/// <inheritdoc/>
@@ -231,7 +231,7 @@ private void HandleHiddenModeUpdate(bool isTriggeredByTextInput)
231231

232232
UpdateWithLock(() =>
233233
{
234-
SetCurrentValue(TextProperty, new string(PasswordChar, newPassword.Length));
234+
SetCurrentValue(TextProperty, new string(PasswordChar, newPassword?.Length ?? 0));
235235
SetCurrentValue(PasswordProperty, newPassword);
236236
CaretIndex = caretIndex;
237237
RaisePasswordChangedEvent();

0 commit comments

Comments
 (0)