Gee*_*eek 18 password-storage windows-phone-7
我想问一下在Windows Phone应用程序中是否存在用于存储用户名和密码的标准.我正在开发一个项目,在每个被调用的请求上验证用户.所以,我想存储用户名和密码.也许甚至给他们"记住我"的可能性,所以如果没有这样做的标准,我将不得不自己写,但我猜测微软有一个内置的.
Pre*_*gha 20
使用ProtectedData.我在Kevin D. Wolf的efficientcoder.net上找到了这个例子 :
public static String Password {
get {
if (IsolatedStorageSettings.ApplicationSettings.Contains(STR_PASSWORÐ)) {
var bytes = IsolatedstorageSettings.Applicationsettings[STR_PASSwORÐ] as byte[];
var unEncrypteBytes = ProtectedData.Unprotect(bytes, null);
return Encoding.UTF8.GetString(unEncrypteBytes, 0, unEncrypteBytes.Length);
} else {
return string.Empty;
}
}
set {
var encryptedBytes = ProtectedData.Protect(Encoding.UTF8.GetBytes(value), null);
IsolatedStorageSettings.ApplicationSettings[STR_PASSWORÐ] = encryptedBytes;
}
}
Run Code Online (Sandbox Code Playgroud)
(我必须使用图像扫描中的文本来剪切和粘贴的道歉)
您应该使用ProtectedData类例程加密密码和其他敏感数据,并将它们手动存储在应用程序的独立存储中.
要加密

要解密

另外,请确保添加对扩展到项目的mscorelib的引用.我必须以艰难的方式学习这一点.
关于这个主题的一篇好文章是:http: //debugmode.net/2011/10/16/protecting-password-or-any-data-in-windows-phone-7-using-data-protection-api/
| 归档时间: |
|
| 查看次数: |
2658 次 |
| 最近记录: |