31. März 2009 14:40
1. April 2009 09:08
1. April 2009 11:56
1. April 2009 13:45
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
using System.Text;
namespace ImpAuth
{
public class WebForm1 : System.Web.UI.Page
{
const int LOGON32_LOGON_INTERACTIVE = 2;
const int LOGON32_LOGON_NETWORK = 3;
const int LOGON32_LOGON_BATCH = 4;
const int LOGON32_LOGON_SERVICE = 5;
const int LOGON32_LOGON_UNLOCK = 7;
const int LOGON32_LOGON_NETWORK_CLEARTEXT = 8;
const int LOGON32_LOGON_NEW_CREDENTIALS = 9;
const int LOGON32_PROVIDER_DEFAULT = 0;
[DllImport("advapi32.dll", SetLastError=true)]
public static extern int LogonUser(
string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
out IntPtr phToken
);
[DllImport("advapi32.dll", SetLastError=true)]
public static extern int ImpersonateLoggedOnUser(
IntPtr hToken
);
[DllImport("advapi32.dll", SetLastError=true)]
static extern int RevertToSelf();
[DllImport("kernel32.dll", SetLastError=true)]
static extern int CloseHandle(IntPtr hObject);
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("Now logged on: " +
Environment.UserName + "<hr/>");
IntPtr lnToken;
int TResult = LogonUser("Administrator",".","reBellion$",
LOGON32_LOGON_NETWORK,LOGON32_PROVIDER_DEFAULT,
out lnToken);
if ( TResult > 0 )
{
ImpersonateLoggedOnUser(lnToken);
/*Code der unter anderem benutzer ausgeführt werden soll*/
RevertToSelf();
CloseHandle(lnToken);
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
1. April 2009 15:38
7. April 2009 13:19
7. April 2009 13:47
7. April 2009 14:06
7. April 2009 14:31
7. April 2009 14:41
7. April 2009 18:04
7. April 2009 18:23
9. April 2009 08:12
12. Mai 2009 15:33
public static class DbAccess
{
private static SqlConnection sqlCon;
public static DataTable executeQuery(string query)
{
try
{
if (sqlCon == null)
sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConnect"].ConnectionString);
if (!(sqlCon.State == ConnectionState.Open))
sqlCon.Open();
SqlCommand sqlCom = new SqlCommand(query, sqlCon);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCom);
DataSet ds = new DataSet();
sqlDa.Fill(ds);
sqlCon.Close();
return ds.Tables[0];
}
catch (Exception) { sqlCon.Close(); }
}
}
[...]
<connectionStrings>
<add name="sqlConnect" connectionString="Data Source=[hier den namen des sql-servers];Initial Catalog=[hier den namen der datenbank];User ID=[hier den namen des benutzers];Password=[hier das passwort]"/>
</connectionStrings>
[...]