Click here to Skip to main content
15,889,281 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Month to month comparison report options Pin
Christian Graus7-Oct-07 11:51
protectorChristian Graus7-Oct-07 11:51 
GeneralRe: Month to month comparison report options Pin
.NET_Labview7-Oct-07 11:57
.NET_Labview7-Oct-07 11:57 
GeneralRe: Month to month comparison report options Pin
Christian Graus7-Oct-07 12:13
protectorChristian Graus7-Oct-07 12:13 
GeneralRe: Month to month comparison report options [modified] Pin
.NET_Labview8-Oct-07 4:23
.NET_Labview8-Oct-07 4:23 
GeneralRe: Month to month comparison report options Pin
.NET_Labview11-Oct-07 3:41
.NET_Labview11-Oct-07 3:41 
GeneralRe: Month to month comparison report options Pin
.NET_Labview11-Oct-07 5:01
.NET_Labview11-Oct-07 5:01 
AnswerRe: Set Null in Ms Access DB Pin
pmarfleet7-Oct-07 10:11
pmarfleet7-Oct-07 10:11 
QuestionLog in Page ( help please ) Pin
Al-jaberi7-Oct-07 7:22
Al-jaberi7-Oct-07 7:22 
please have a look to my code.I always have error invalid user name or passwprd , can you help me please.if oyu want me to send you the whole project please let me know.

private void Page_Load(object sender, System.EventArgs e)
{

}
private static string CreateSalt(int size)
{
// Generate a cryptographic random number using the cryptographic
// service provider
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
byte[] buff = new byte[size];
rng.GetBytes(buff);
// Return a Base64 string representation of the random number
return Convert.ToBase64String(buff);
}
private static string CreatePasswordHash(string pwd, string salt)
{
string saltAndPwd = String.Concat(pwd, salt);
string hashedPwd =
FormsAuthentication.HashPasswordForStoringInConfigFile(
saltAndPwd, "SHA1");
hashedPwd = String.Concat(hashedPwd, salt);
return hashedPwd;
}

#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);
}

private void InitializeComponent()
{
this.btnLogon.Click += new System.EventHandler(this.btnLogon_Click);
this.btnRegister.Click += new System.EventHandler(this.btnRegister_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnRegister_Click(object sender, System.EventArgs e)
{
int saltSize = 5;
string salt = CreateSalt(saltSize);
string passwordHash = CreatePasswordHash(txtPassword.Text,salt);
try
{
StoreAccountDetails( txtUserName.Text, passwordHash);
}
catch(Exception ex)
{
lblMessage.Text = ex.Message;
}
}
private bool VerifyPassword(string suppliedUserName,
string suppliedPassword )
{
bool passwordMatch = false;
// Get the salt and pwd from the database based on the user name.
SqlConnection conn = new SqlConnection( "Server=(local);" +"Integrated Security=SSPI;" + "database=UserAccounts");
SqlCommand cmd = new SqlCommand( "LookupUser", conn );
cmd.CommandType = CommandType.StoredProcedure;

SqlParameter sqlParam = cmd.Parameters.Add("@userName",
SqlDbType.VarChar,
20);
sqlParam.Value = suppliedUserName;
try
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
reader.Read(); // Advance to the one and only row
// Return output parameters from returned data stream
string dbPasswordHash = reader.GetString(0);
int saltSize = 5;
string salt =
dbPasswordHash.Substring(dbPasswordHash.Length - saltSize);
reader.Close();
// Now take the password supplied by the user
// and generate the hash.
string hashedPasswordAndSalt =
CreatePasswordHash(suppliedPassword, salt);
// Now verify them.
passwordMatch = hashedPasswordAndSalt.Equals(dbPasswordHash);
}
catch (Exception ex)
{
throw new Exception("Execption verifying password. " +
ex.Message);
}
finally
{
conn.Close();
}
return passwordMatch;
}
private void StoreAccountDetails( string userName,
string passwordHash )
{
// See "How To Use DPAPI (Machine Store) from ASP.NET" for information
// about securely storing connection strings.
SqlConnection conn = new SqlConnection( "Server=(local);" + "Integrated Security=SSPI;" +
"database=UserAccounts");

SqlCommand cmd = new SqlCommand("RegisterUser", conn );
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter sqlParam = null;
//Usage of Sql parameters also helps avoid SQL Injection attacks.
sqlParam = cmd.Parameters.Add("@userName", SqlDbType.VarChar,
20);
sqlParam.Value = userName;

sqlParam = cmd.Parameters.Add("@passwordHash ", SqlDbType.VarChar,
40);
sqlParam.Value = passwordHash;

try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch( Exception ex )
{
// Code to check for primary key violation (duplicate account

// or other database errors omitted for clarity
throw new Exception("Exception adding account. " + ex.Message);
}
finally
{
conn.Close();
}
}

private void btnLogon_Click(object sender, System.EventArgs e)
{
bool passwordVerified = false;
try
{
passwordVerified =
VerifyPassword(txtUserName.Text,txtPassword.Text);
}
catch(Exception ex)
{
lblMessage.Text = ex.Message;
return;
}
if (passwordVerified == true )
{
lblMessage.Text = "Logon successful: User is authenticated";
}
else
{
lblMessage.Text = "Invalid username or password";
}
}

AnswerRe: Log in Page ( help please ) Pin
mr.mohsen7-Oct-07 10:14
mr.mohsen7-Oct-07 10:14 
GeneralRe: Log in Page ( help please ) Pin
Al-jaberi7-Oct-07 16:55
Al-jaberi7-Oct-07 16:55 
Questionhow can i insert mpeg files to the database? Pin
ebtihal7-Oct-07 5:16
ebtihal7-Oct-07 5:16 
AnswerRe: how can i insert mpeg files to the database? Pin
Christian Graus7-Oct-07 10:25
protectorChristian Graus7-Oct-07 10:25 
Questionaccess to server controls by javascript???????????? Pin
mr.mohsen7-Oct-07 5:12
mr.mohsen7-Oct-07 5:12 
AnswerRe: access to server controls by javascript? Pin
Guffa7-Oct-07 5:29
Guffa7-Oct-07 5:29 
GeneralRe: access to server controls by javascript? Pin
mr.mohsen7-Oct-07 7:00
mr.mohsen7-Oct-07 7:00 
GeneralRe: access to server controls by javascript? Pin
Christian Graus7-Oct-07 10:26
protectorChristian Graus7-Oct-07 10:26 
Questionasp:CompleteWizardStep Continue Button Pin
Brendan Vogt7-Oct-07 1:57
Brendan Vogt7-Oct-07 1:57 
Questionimage not work in firefox Pin
samforu7-Oct-07 1:07
samforu7-Oct-07 1:07 
AnswerRe: image not work in firefox Pin
Parwej Ahamad7-Oct-07 18:32
professionalParwej Ahamad7-Oct-07 18:32 
QuestionCould not load assembly Pin
IamAmit7-Oct-07 1:00
IamAmit7-Oct-07 1:00 
QuestionSQL server 2005 with Enterprise Library 1.1 Pin
asif m@hmood6-Oct-07 23:16
asif m@hmood6-Oct-07 23:16 
AnswerRe: SQL server 2005 with Enterprise Library 1.1 Pin
Christian Graus6-Oct-07 23:24
protectorChristian Graus6-Oct-07 23:24 
GeneralRe: SQL server 2005 with Enterprise Library 1.1 Pin
asif m@hmood6-Oct-07 23:29
asif m@hmood6-Oct-07 23:29 
Questionhow can recognize in asp.net when user exit from a page ? Pin
B.A6-Oct-07 22:57
B.A6-Oct-07 22:57 
AnswerRe: how can recognize in asp.net when user exit from a page ? Pin
Christian Graus6-Oct-07 23:25
protectorChristian Graus6-Oct-07 23:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.