PasswordBoxコントロールのPasswordプロパティが依存関係プロパティとして実装されていない理由

PasswordBox が Binding できない



 WPFのPasswordBoxコントロールのPasswordプロパティは、依存関係プロパティとして実装されていないためデータバインディングを利用することができません。私も気になって調べてみたところ、セキュリティ的な理由によりあえてCLRプロパティとなっているようです。

Unable to data-bind to a PasswordBox


Exposing a DependencyProperty would require us to store the PasswordBox content plain text in memory in the property system -- which is a security concern. The PasswordBox encrypts its content and only generates plain text on demand when a caller references the Password CLR property.


依存関係プロパティとして公開した場合、プロパティシステムにおいてPasswordBoxのコンテンツを平文としてメモリ上に格納する必要があるというセキュリティ上の問題が発生します。PasswordBoxはそのコンテンツを暗号化し、呼び出し元がPasswordプロパティ(CLRプロパティ)を参照する場合にのみ、必要に応じて平文が生成されます。



 これに関連したことがMSDNライブラリのPasswordBox.Passwordプロパティのページにも記載されています。

PasswordBox.Password プロパティ (System.Windows.Controls)


Password プロパティ値を取得すると、パスワードをメモリ内にプレーンテキストとして公開することになります。 この潜在的なセキュリティ リスクを回避するために、SecurePassword プロパティを使用して、パスワードを SecureString として取得します。



 という記載がありますので、.NET Framework 3.5 SP1から追加されたSecurePasswordプロパティを使用して、値をSecureStringオブジェクトとして扱うようにするのが良いようです。