我需要帮助 [英] I need help with something

查看:72
本文介绍了我需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,让我尽力解释这个问题。我正在创建这个

应用程序,其中包含一个userlogin类。用户在进入主要apploication之前登录

。我想做审计跟踪,我想知道如何获取登录的用户ID。可以

任何人帮助我。


我有样品,如果有人需要它们。

Ok let me try to explain this as good as I can. I am creating this
application where it contains a userlogin class. The user logs in
before entering the main apploication. I want to do audit trails and I
am trying to figure out how to get the user ID that logged in. Can
anyone help me.

I have samples if anyone needs them.

推荐答案

嗨马修,


userlogin类从哪里获取用户的数据?

用户ID是什么意思?您是指数据库列或Web服务返回值,例如?

或者您只是在寻找一种方法来识别登录ASP.NET程序的Windows用户?

也许你正在运行一个使用LDAP登录其用户的WinForms应用程序?


你需要提供这些答案,至少,如果有人要去能够帮助你。


见Jon''s Skeets文章: http://www.yoda.arachsys.com/csharp/complete.html
Hi Matthew,

Where does the userlogin class get the user''s data from?
And what do you mean by user ID? Are you referring to a database column or web service return value, for example?
Or are you just looking for a way to identify the Windows user that logged into your ASP.NET program?
Perhaps you''re running a WinForms application that uses LDAP to login its users?

You''ll need to supply these answers, at least, if anyone is going to be able to help you.

See Jon''s Skeets article: http://www.yoda.arachsys.com/csharp/complete.html

我有样品,如果有人需要它们。
I have samples if anyone needs them.



可能有用。如果有人要确定

示例的有用性,你将不得不提供有关手头问题的更多信息。


-

Dave Sexton


" Matthew" < ma ****** @ yahoo.com在留言新闻中写道:11 ********************** @ m73g2000cwd.googlegr oups.com ...

Might be useful. You''ll have to supply more information about the problem at hand if anyone is going to determine the usefulness of
examples.

--
Dave Sexton

"Matthew" <ma******@yahoo.comwrote in message news:11**********************@m73g2000cwd.googlegr oups.com...


好​​的,让我尽力解释这个问题。我正在创建这个

应用程序,其中包含一个userlogin类。用户在进入主要apploication之前登录

。我想做审计跟踪,我想知道如何获取登录的用户ID。可以

任何人帮助我。


我有样品,如果有人需要它们。
Ok let me try to explain this as good as I can. I am creating this
application where it contains a userlogin class. The user logs in
before entering the main apploication. I want to do audit trails and I
am trying to figure out how to get the user ID that logged in. Can
anyone help me.

I have samples if anyone needs them.



嘿戴夫,


这是一个Windows应用程序,首先是我使用C#。

userlogin类本身是一个单独的类,ID是

公共属性之一用户登录类。


逻辑是这样的。


应用程序启动并登录屏幕加载。用户

输入他们的ID和密码,然后按下llogin按钮,

userlogin类进行身份验证。如果验证

通过,则登录屏幕卸载并且主屏幕加载。

USERLOGIN CLASS:


命名空间RegIT.RegitClasses

{

///< summary>

/// UserLogin的摘要说明。

// /< / summary>

///


公共类regitUserLogin

{

private int uloginID;

private string uloginEmpNumber;

private string uloginPassword;

private string uloginCreateDate;

private string uloginChangeDate ;

私有字符串uloginChangeBy;

private regitUserLogin [] uloginList;

private string strEncrKey =" m74r95c96 =" ;;

public string PassWordHash;


public int ID

{

get {return uloginID;}

set {uloginID = value;}

}

public string EmpNumber

{

get { return uloginEmpNumber;}

set {uloginEmpNumber = value;}

}

公共字符串密码

{

get {return uloginPassword;}

set

{

uloginPassword = value;

uloginPassword = EncryptedPassword;

}

}

公共字符串CreateDate

{

get {return uloginCreateDate;}

set {uloginCreateDate = Convert.ToString(value);}

}

public string ChangeDate

{

get {return uloginChangeDate;}

set {uloginChangeDate = Convert.ToString(value);}

}

public string ChangeBy

{

get {return uloginChangeBy;}

set {uloginChangeBy = value;}

}

public regitUserLogin [] LoginList

{

get {return uloginList;}

set {uloginList = value;}

}

私人字符串EncryptedPassword

{


get {return Encrypt(strEncrKey,out uloginPassword);}

}


受保护的字符串加密(字符串EncryptionKey,out string

uloginPassword)

{

byte [] byteKey = Encoding.UTF8.GetBytes(EncryptionKey);

string regitPWD =密码;

HMACSHA1 hmac = new HMACSHA1(byteKey);


byte [] bytePWD = Encoding.UTF8.GetBytes(regitPWD);

byte [] byteHash = hmac.ComputeHash(bytePWD);

uloginPassword = Convert.ToBase64String(byteHash);


返回uloginPassword;

}


public bool regitAuthenticateLogin( string EmpNumber,string Password)

{

regitDatabase regitDB = new regitDatabase();

SqlParameter [] regitParams = new SqlParameter [2];

SqlDataReader regitDR = null;

尝试

{

string compareENum ="" ;;

string compareEPwd ="" ;;


regitParams [0] = regitDB.regitMakeParameter(" @EnNumber",

Conv ert.ToString(EmpNumber).Trim());

regitParams [1] = regitDB.regitMakeParameter(" @ EmpPassword",

Convert.ToString(Password)。修剪());

regitDB.regitRunProcedure(" regit_sp_Get_UserLogin_ Authentication",

regitParams,ref regitDR);


while (regitDR.Read())

{

compareENum = regitDR [" emp_Number"]。ToString();

compareEPwd = regitDR [ " emp_Password"]。ToString();

}

regitDR.Close();

regitDB.regitConnectionClose();

regitDB.regitConnectionDispose();


if(compareENum == EmpNumber&& compareEPwd ==密码)

{

返回true;

}

其他

{

返回false;

}

}

catch(例外情况)

{

throw(ex);

返回false;

}

终于

{

regitDR.Close();

regitDB.regitConnectionClose();

regitDB.regitConnectionDispose();

regitParams = null;

}

}

public bool regitCreateLogin(string EmpNumber,string Password)

{

regitDatabase regitDB = new regitDatabase();

SqlParameter [] regitParams = new SqlParameter [2];


尝试

{

regitParams [0] = regitDB.regitMakeParameter(" @ EmpNumber",

EmpNumber);

regitParams [1] = regitDB.regitMakeParameter(" @ EmpPassword",

密码);

regitDB.regitRunProcedure(" regit_sp_Add_UserLogin",regitParams);


返回true;

}

catch(SqlException sqlex)

{

throw(sqlex);

}

catch

{return false;}

终于

{

regitParams = null;

regitDB.regitConnectionClose();

regitDB.regitConnectionDispose();

}

}

}

}

Hey Dave,

This is a windows application first and foremost and I am using C#.
the userlogin class is a seperate class by itself, the ID is one of the
public properties of the userlogin class.

The logic goes like this.

The application starts up and the login screen loads up. The user
enters their ID and password, and presses llogin button, where the
userlogin class does the authentication. and if the authentication
passes then the login screen unloads and themain screen loads.
USERLOGIN CLASS:

namespace RegIT.RegitClasses
{
/// <summary>
/// Summary description for UserLogin.
/// </summary>
///

public class regitUserLogin
{
private int uloginID;
private string uloginEmpNumber;
private string uloginPassword;
private string uloginCreateDate;
private string uloginChangeDate;
private string uloginChangeBy;
private regitUserLogin[] uloginList;
private string strEncrKey = "m74r95c96=";
public string PassWordHash;

public int ID
{
get{return uloginID;}
set{uloginID = value;}
}
public string EmpNumber
{
get{return uloginEmpNumber;}
set{uloginEmpNumber = value;}
}
public string Password
{
get{return uloginPassword;}
set
{
uloginPassword = value;
uloginPassword = EncryptedPassword;
}
}
public string CreateDate
{
get{return uloginCreateDate;}
set{uloginCreateDate = Convert.ToString(value);}
}
public string ChangeDate
{
get{return uloginChangeDate;}
set{uloginChangeDate = Convert.ToString(value);}
}
public string ChangeBy
{
get{return uloginChangeBy;}
set{uloginChangeBy = value;}
}
public regitUserLogin[] LoginList
{
get{return uloginList;}
set{uloginList=value;}
}
private string EncryptedPassword
{

get{return Encrypt(strEncrKey, out uloginPassword);}
}

protected string Encrypt(string EncryptionKey,out string
uloginPassword)
{
byte[] byteKey = Encoding.UTF8.GetBytes(EncryptionKey);
string regitPWD = Password;
HMACSHA1 hmac = new HMACSHA1(byteKey);

byte[] bytePWD = Encoding.UTF8.GetBytes(regitPWD);
byte[] byteHash = hmac.ComputeHash(bytePWD);
uloginPassword = Convert.ToBase64String(byteHash);

return uloginPassword;
}

public bool regitAuthenticateLogin(string EmpNumber, string Password)
{
regitDatabase regitDB = new regitDatabase();
SqlParameter[] regitParams = new SqlParameter[2];
SqlDataReader regitDR = null;
try
{
string compareENum = "";
string compareEPwd = "";

regitParams[0] = regitDB.regitMakeParameter("@EmpNumber",
Convert.ToString(EmpNumber).Trim());
regitParams[1] = regitDB.regitMakeParameter("@EmpPassword",
Convert.ToString(Password).Trim());
regitDB.regitRunProcedure("regit_sp_Get_UserLogin_ Authentication",
regitParams, ref regitDR);

while(regitDR.Read())
{
compareENum = regitDR["emp_Number"].ToString();
compareEPwd = regitDR["emp_Password"].ToString();
}
regitDR.Close();
regitDB.regitConnectionClose();
regitDB.regitConnectionDispose();

if(compareENum==EmpNumber && compareEPwd==Password)
{
return true;
}
else
{
return false;
}
}
catch(Exception ex)
{
throw(ex);
return false;
}
finally
{
regitDR.Close();
regitDB.regitConnectionClose();
regitDB.regitConnectionDispose();
regitParams = null;
}
}
public bool regitCreateLogin(string EmpNumber, string Password)
{
regitDatabase regitDB = new regitDatabase();
SqlParameter[] regitParams = new SqlParameter[2];

try
{
regitParams[0] = regitDB.regitMakeParameter("@EmpNumber",
EmpNumber);
regitParams[1] = regitDB.regitMakeParameter("@EmpPassword",
Password);
regitDB.regitRunProcedure("regit_sp_Add_UserLogin" , regitParams);

return true;
}
catch(SqlException sqlex)
{
throw(sqlex);
}
catch
{return false;}
finally
{
regitParams = null;
regitDB.regitConnectionClose();
regitDB.regitConnectionDispose();
}
}
}
}


马修,


你的逻辑听起来不错,但你还没有问过任何问题。你需要什么帮助?


-

Dave Sexton


" Matthew" < ma ****** @ yahoo.com在留言新闻中写道:11 ********************** @ m7g2000cwm.googlegro ups.com ...
Hi Matthew,

Your "logic" sounds fine but you haven''t asked any questions yet. What do you need help with?

--
Dave Sexton

"Matthew" <ma******@yahoo.comwrote in message news:11**********************@m7g2000cwm.googlegro ups.com...

Hey Dave,


这首先是Windows应用程序,我正在使用C#。

userlogin类本身是一个单独的类,ID是userlogin类的

公共属性之一。


逻辑就像这个。


应用程序启动并登录屏幕加载。用户

输入他们的ID和密码,然后按下llogin按钮,

userlogin类进行身份验证。如果验证

通过,则登录屏幕卸载并且主屏幕加载。


USERLOGIN CLASS:


namespace RegIT.RegitClasses

{

///< summary>

/// UserLogin的摘要说明。

///< / summary>

///


公共类regitUserLogin

{

private int uloginID;

private string uloginEmpNumber;

private string uloginPassword;

private string uloginCreateDate;

private string uloginChangeDate;

private string uloginChangeBy;

private regitUserLogin [] uloginList;

private string strEncrKey =" m74r95c96 =" ;;

公共字符串PassWordHash;


public int ID

{

get {return uloginID;}

set {uloginID = value;}

}

public string EmpNumber

{

get {return uloginEmpNumber;}

set {uloginEmpNumber = value;}

}

公共字符串密码

{

get {return uloginPassword;}

set

{

uloginPassword = value;

uloginPassword = EncryptedPassword;

}

}

公共字符串CreateDate

{

get {return uloginCreateDate;}

set {uloginCreateDate = Convert.ToString(value);}

}

公共字符串ChangeDate

{

get {return uloginChangeDate;}

set {uloginChangeDate = Convert.ToString(value);}

}

公共字符串ChangeBy

{

get {return uloginChangeBy;}

set {uloginChangeBy = value;}

}

public regitUserLogin [] LoginList

{

get {return uloginList;}

set {uloginList = value;}

}

私有字符串EncryptedPassword

{


get {return Encrypt(strEncrKey,out uloginPassword);}

}


受保护的字符串加密(字符串EncryptionKey,out string

uloginPassword)

{

byte [] byteKey = Encoding.UTF8.GetBytes(EncryptionKey);

string regitPWD =密码;

HMACSHA1 hmac = new HMACSHA1(byteKey);


byte [] bytePWD = Encoding.UTF8.GetBytes(regitPWD);

byte [] byteHash = hmac.ComputeHash(bytePWD);

uloginPassword = Convert.ToBase64String(byteHash);


返回uloginPassword;

}


public bool regitAuthenticateLogin(字符串EmpNumber,字符串密码)

{

regitDatabase regitDB = new regitDatabase();

SqlParameter [] regitParams = new SqlParameter [2 ];

SqlDataReader regitDR = null;

尝试

{

string compareENum ="" ;;

string compareEPwd ="" ;;


regitParams [0] = regitDB.regitMakeParameter(" @EnNumber",

兑换.ToString(EmpNumber).Trim());

regitParams [1] = regitDB.regitMakeParameter(" @ EmpPassword",

Convert.ToString(Password).Trim ());

regitDB.regitRunProcedure(" regit_sp_Get_UserLogin_ Authentication",

regitParams,ref regitDR);


while( regitDR.Read())

{

compareENum = regitDR [" emp_Number"]。ToString();

compareEPwd = regitDR [" ; emp_Password"]。ToString();

}

regitDR.Close();

regitDB.regitConnectionClose();

regitDB.regitConnectionDispose();


if(compareENum == EmpNumber&& compareEPwd ==密码)

{

返回true;

}

其他

{

返回false;

}

}

catch(例外情况)

{

throw(ex);

返回false;

}

终于

{

regitDR.Close();

regitDB.regitConnectionClose();

regitDB.regitConnectionDispose();

regitParams = null;

}

}

public bool regitCreateLogin(string EmpNumber,string Password)

{

regitDatabase regitDB = new regitDatabase();

SqlParameter [] regitParams = new SqlParameter [2];


尝试

{

regitParams [0] = regitDB.regitMakeParameter(" @ EmpNumber",

EmpNumber);

regitParams [1] = regitDB.regitMakeParameter(" @ EmpPassword",

密码);

regitDB.regitRunProcedure(" regit_sp_Add_UserLogin",regitParams);


返回true;

}

catch(SqlException sqlex)

{

throw(sqlex);

}

catch

{return false;}

终于

{

regitParams = null;

regitDB.regitConnectionClose();

regitDB.regitConnectionDispose();

}

}

}

}
Hey Dave,

This is a windows application first and foremost and I am using C#.
the userlogin class is a seperate class by itself, the ID is one of the
public properties of the userlogin class.

The logic goes like this.

The application starts up and the login screen loads up. The user
enters their ID and password, and presses llogin button, where the
userlogin class does the authentication. and if the authentication
passes then the login screen unloads and themain screen loads.
USERLOGIN CLASS:

namespace RegIT.RegitClasses
{
/// <summary>
/// Summary description for UserLogin.
/// </summary>
///

public class regitUserLogin
{
private int uloginID;
private string uloginEmpNumber;
private string uloginPassword;
private string uloginCreateDate;
private string uloginChangeDate;
private string uloginChangeBy;
private regitUserLogin[] uloginList;
private string strEncrKey = "m74r95c96=";
public string PassWordHash;

public int ID
{
get{return uloginID;}
set{uloginID = value;}
}
public string EmpNumber
{
get{return uloginEmpNumber;}
set{uloginEmpNumber = value;}
}
public string Password
{
get{return uloginPassword;}
set
{
uloginPassword = value;
uloginPassword = EncryptedPassword;
}
}
public string CreateDate
{
get{return uloginCreateDate;}
set{uloginCreateDate = Convert.ToString(value);}
}
public string ChangeDate
{
get{return uloginChangeDate;}
set{uloginChangeDate = Convert.ToString(value);}
}
public string ChangeBy
{
get{return uloginChangeBy;}
set{uloginChangeBy = value;}
}
public regitUserLogin[] LoginList
{
get{return uloginList;}
set{uloginList=value;}
}
private string EncryptedPassword
{

get{return Encrypt(strEncrKey, out uloginPassword);}
}

protected string Encrypt(string EncryptionKey,out string
uloginPassword)
{
byte[] byteKey = Encoding.UTF8.GetBytes(EncryptionKey);
string regitPWD = Password;
HMACSHA1 hmac = new HMACSHA1(byteKey);

byte[] bytePWD = Encoding.UTF8.GetBytes(regitPWD);
byte[] byteHash = hmac.ComputeHash(bytePWD);
uloginPassword = Convert.ToBase64String(byteHash);

return uloginPassword;
}

public bool regitAuthenticateLogin(string EmpNumber, string Password)
{
regitDatabase regitDB = new regitDatabase();
SqlParameter[] regitParams = new SqlParameter[2];
SqlDataReader regitDR = null;
try
{
string compareENum = "";
string compareEPwd = "";

regitParams[0] = regitDB.regitMakeParameter("@EmpNumber",
Convert.ToString(EmpNumber).Trim());
regitParams[1] = regitDB.regitMakeParameter("@EmpPassword",
Convert.ToString(Password).Trim());
regitDB.regitRunProcedure("regit_sp_Get_UserLogin_ Authentication",
regitParams, ref regitDR);

while(regitDR.Read())
{
compareENum = regitDR["emp_Number"].ToString();
compareEPwd = regitDR["emp_Password"].ToString();
}
regitDR.Close();
regitDB.regitConnectionClose();
regitDB.regitConnectionDispose();

if(compareENum==EmpNumber && compareEPwd==Password)
{
return true;
}
else
{
return false;
}
}
catch(Exception ex)
{
throw(ex);
return false;
}
finally
{
regitDR.Close();
regitDB.regitConnectionClose();
regitDB.regitConnectionDispose();
regitParams = null;
}
}
public bool regitCreateLogin(string EmpNumber, string Password)
{
regitDatabase regitDB = new regitDatabase();
SqlParameter[] regitParams = new SqlParameter[2];

try
{
regitParams[0] = regitDB.regitMakeParameter("@EmpNumber",
EmpNumber);
regitParams[1] = regitDB.regitMakeParameter("@EmpPassword",
Password);
regitDB.regitRunProcedure("regit_sp_Add_UserLogin" , regitParams);

return true;
}
catch(SqlException sqlex)
{
throw(sqlex);
}
catch
{return false;}
finally
{
regitParams = null;
regitDB.regitConnectionClose();
regitDB.regitConnectionDispose();
}
}
}
}



这篇关于我需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆