Jus*_*ant 2 .net c# passwords credentials isolatedstorage
最近我一直在使用无线网络的办公室工作,该网络使用恼人的身份验证方案:每隔几个小时,您需要打开浏览器并在身份验证网页中键入用户名/密码,否则您将失去网络访问权限.(当时间到期时,您的下一个浏览器请求将重定向到auth页面,如果您的信用卡通过,则您将被重定向回您最初尝试访问的页面).
对于无线机场或咖啡店来说,这种烦恼可能是好的,但在办公室里,这是令人愤怒的 - 特别是如果你正在使用网络服务(例如SVN,电子邮件),除非你提出一个网络服务突然停止工作每隔几个小时浏览器.
所以我写了一个很小的C#控制台应用程序,它将通过我的凭据向登录表单发送HTTP请求来为我登录.
这显然是不安全的 - 我的密码位于我的源代码中供所有人查看.我希望能够使用与IE相同的机制来保存我的凭据,例如,IE用于保存和重新填写Web表单中的密码.
理想情况下,我想要一个可重复使用的组件来输入,保存和检索凭证(包括带有可选"保存信用"复选框的UI),以便我的应用程序可以简单地执行此类操作(在伪代码中):
// retrieve any saved credentials from some secure place
Credentials creds = GetCreds(some parameters go here);
// if none stored, then show the user an "enter and optionally save credentials" dialog
if (creds == null)
creds = GetCredsDialog(some parameters go here);
// POST to the authentication page
if (creds != null)
{
string authUrl = "https://somehost/login/";
string postDataPattern = "post data pattern here";
// use SecureString here instead?
string postData = string.Format (postDataPattern, HttpUtility.HtmlEncode(creds.Username), HttpUtility.HtmlEncode(creds.Password));
WebClient wc = new WebClient();
string html = wc.UploadString (authUrl, "POST", postData);
// TODO: if html indicates login failure, clear stored credentials
// and ask for new creds. then retry.
}
Run Code Online (Sandbox Code Playgroud)
基本上我想把安全存储信用卡从我的应用程序转移到Windows的负担,假设Windows人员会比我更好.:-)
我不是在寻找这里的铁质安全性,只是与IE用于保护其他网站的其他存储密码的东西相当.我只是不想在我的代码中保留纯文本密码!
当然,这里正确的解决方案是与IT部门合作,让他们为无线获得真正的身份验证方案,但与此同时我自己.
一个.NET解决方案会更好,但Win32解决方案也可以 - 我可以简单地将应用程序移植到C++而不会有太多麻烦.
要存储凭据,请使用System.Security.dll中的ProtectedData类.
通过传递DataProtectionScope.CurrentUser,没有其他用户能够解密数据.
编辑:对于对话框,您可以使用CredUIPromptForCredentials API函数
见这里的.NET包装.
| 归档时间: |
|
| 查看次数: |
1684 次 |
| 最近记录: |