So I'm building a page named "Login" where the person with one account already in database can well do the login and entry in the "main page"
I have 2 Different Rolls: -Admin - Can create others accoutns, edit, delete etc...
-Normal user - Can't create another accounts, and it is just enable to read, not edit, delete etc...
I did a column in sql with the following name "function" where it keeps the roles as numbers...
1-admin
2-Normal User
But I'm not getting how I should use it, I did something like this:
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection sqlcon = new SqlConnection(@"Data Source=PEDRO-PC\SQLEXPRESS;Initial Catalog=costumizado;Integrated Security=True"))
{
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
byte[] buffer = new byte[1024];
rng.GetBytes(buffer);
string salt = BitConverter.ToString(buffer);
var saltedPassword = TextBox2.Text + salt;
string passstr = Encrypt(TextBox2.Text);
// string Select_Query = "SELECT count (*) FROM Usuarios where(Nome = '" + TextBox1.Text + "' and PalavraPasse ='" + passstr + "');";
// Debug.Write(Select_Query);
sqlcon.Close();
using (sqlcon)
{
SqlCommand command = new SqlCommand("SELECT Nome, PalavraPasse, Funcao FROM Usuarios;", sqlcon);
sqlcon.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
if (reader.Read())
{
Debug.WriteLine("{0} {1} {2}",
reader["Nome"],
reader["PalavraPasse"],
reader["Funcao"]);
}
if (reader["Funcao"] == "1")
{
Response.Redirect("~/StartupAdmin.aspx");
}
else if (reader["Funcao"] == "2")
{
Response.Redirect("~/StartupNormal.aspx");
}
}
else
{
Debug.WriteLine("No rows found.");
}
reader.Close();
sqlcon.Close();
}
}
}
ps: I know that doing this:
if (count > 0 && function =="1" )
Doesn't make sense cause "Function" doesnt even is a variable, but but it was to show more or less what I wanted to do Output
No rows found.
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
the 1-1-1 was a user that I created jsut for test