por favor, Podem me ajudar ?
09/11/2011
0
Obrigado.
aqui vai o código;
private bool UserExists(string UserName)
{
//Create a data set to read the XML file.
DataSet dsUsers = new DataSet();
//Use error handling in case is file missing.
try
{
//Build the Users.xml file path.
string strXMLFile = Server.MapPath(.) + \\Users.xml;
//Read the file
dsUsers.ReadXml(strXMLFile, XmlReadMode.InferSchema);
//For each row in the Users table.
foreach (DataRow rowUser in dsUsers.Tables[Users].Rows)
{
//Check for name match.
if (rowUser[name].ToString() == UserName)
{
return true;
}
}
}
catch
{
//In case of error return False.
return false;
}
// Otherwise, return false
return false;
}
private bool PasswordValid(string UserName, string Password)
{
//Create a data set to read the XML file.
DataSet dsUsers = new DataSet();
//Use error handling in case is file missing.
try
{
// Build the Users.xml file path.
string strXMLFile = Server.MapPath(.) + \\Users.xml;
// Read the file
dsUsers.ReadXml(strXMLFile, XmlReadMode.InferSchema);
// For each row in the Users table.
foreach (DataRow rowUser in dsUsers.Tables[Users].Rows)
{
// Check for name match.
if (rowUser[name].ToString() == UserName)
{
if (rowUser[password].ToString() ==
FormsAuthentication.HashPasswordForStoringInConfigFile(Password, SHA1))
{
return true;
}
}
}
}
catch
{
// In case of error return False.
return false;
}
return false;
}
Willian Carvalho
Posts
10/11/2011
Evandro Lopes
/// <summary> /// /// </summary> /// <param name=UserName></param> /// <param name=Password></param> /// <returns></returns> private bool PasswordValid(string UserName, string Password) { try { //Verifica se o usuario existe passando como parametro o usuario e a senha discriptografada if (UserExists(UserExists, FormsAuthentication.HashPasswordForStoringInConfigFile(Password, SHA1))) { return true; } else { return false; } } catch { // In case of error return False. return false; } return false; } /// <summary> /// /// </summary> /// <param name=UserName></param> /// <param name=Password></param> /// <returns></returns> private bool UserExists(string UserName, string Password) { //Cria a conexão com banco de dados SqlConnection conexao = new SqlConnection(string de conexao com BD); try { //cria a consulta para verificar usuario e senha string select = string.Format(SELECT COUNT(*) as qtdUsuario FROM TABELA WHERE usuario = AND password = , UserName, Password); SqlCommand comm = new SqlCommand(select, conexao); if (conexao.State == ConnectionState.Closed) { conexao.Open(); } using (IDataReader reader = comm.ExecuteReader()) { while (reader.Read()) { if (reader.GetInt32(reader.GetOrdinal(qtdUsuario)) > 0) { return true; } else { return false; } } } } catch { //In case of error return False. return false; } finally { if (conexao.State == ConnectionState.Open()) { conexao.Close(); } } // Otherwise, return false return false; }
10/11/2011
Willian Carvalho
Clique aqui para fazer login e interagir na Comunidade :)