使用Windows窗体应用程序自动登录用户?
答
拿起密码是永远不可能的,因为它是一个安全威胁。 。
根据您的WinForms应用程序编写语言,可能有几种方法来获得当前登录用户的用户名
在C#中,你可以这样说:
string username = Environment.UserName;
string domain = Environment.UserDomainName;
string fullyQualifiedUsername = domain + "\\" + username;
有一次,你有用户名,你可以假设用户在登录到机器时已经被认证。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Activities.Statements;
public partial class sso : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string username = Request["username"];
FormsAuthentication.RedirectFromLoginPage(username, false);
}
}
然后,您可以调用页面这样:http://localhost/sso/sso.aspx?username=Varun+Chatterji
因此,你就可以绕过ASP.NET通过创建“日志中的”用户上面得到一个自定义页面表单认证免责声明:这是示例代码,不适用于生产。如果实现单独使用查询字符串以这种方式“登录”,则必须在sso.aspx
答
您可以随时检查,看看是否有一个有效的WindowsIdentity
:
using System.Security.Principal;
WindowsIdentity currUser = WindowsIdentity.GetCurrent();
if (currUser != null)
{
string userName = currUser.Name;
}
但人也说:你赢了无法检索密码 - 永远不会。
连接字符串和当前的Windows身份如果你想登录到SQL Server,你可以定义Integrated Security=SSPI;
将用于登录到SQL Server。没有密码需要这个。
登录到什么某种形式的认证安全登录?针对哪种用户需要验证凭据? – rene 2011-03-16 06:53:50
该应用程序必须在Intranet中使用。它将使用凭证登录,然后我将使用该应用与网站进行交互。 – Prachur 2011-03-16 06:58:58