【发布时间】:2014-02-09 06:29:51
【问题描述】:
绑定到 PasswordBox 的问题,这是一个安全风险,但我使用的是 MVVM 模式,我在这里找到了一些有趣的代码
http://www.wpftutorial.net/PasswordBox.html
我的 LoginViewModel 中基本上有用于用户名和密码的属性。用户名很好,因为它是一个文本框。
我使用上面的代码并输入了这个
<PasswordBox ff:PasswordHelper.Attach="True"
ff:PasswordHelper.Password="{Binding Path=Password}" Width="130"/>
当我将 PasswordBox 作为 TextBox 并且 Binding Path=Password 时,我的 LoginViewModel 中的属性已更新。
我的代码很简单,基本上我的按钮有一个命令。当我按下它时,会调用 CanLogin,如果它返回 true,则调用 Login。 你可以看到我在这里检查了我的用户名属性,效果很好。
在登录时,我向我的服务发送用户名和密码,用户名包含来自我的视图的数据,但密码为 Null|Empty
<TextBox Text="{Binding Path=Username, UpdateSourceTrigger=PropertyChanged}"
MinWidth="180" />
<PasswordBox ff:PasswordHelper.Attach="True"
ff:PasswordHelper.Password="{Binding Path=Password}" Width="130"/>
我有我的 TextBox,这没问题,但在我的 ViewModel 中,密码为空。
我放了一个断点,果然代码进入了静态帮助类,但它从不更新我的 ViewModel 中的密码
【问题讨论】:
标签: c# asp.net wpf mvvm passwords