Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Contributor
3052 Points
2402 Posts
Apr 23, 2012 02:47 AM|LINK
Here is my class file:
using System; using Npgsql; using System.Data; namespace DataAccess { class Class1 { private int _uid; private bool _auth; public int UID { get { return _uid; } set { _uid = value; } } public bool AUTH { get { return _auth; } set { _auth = value; } } private string _dbConn { get { return "Server=xxxxxxxx;Port=xxxxx;User Id=xxxxxx;Password=xxxxxx;Database=xxxxxxx;"; } } public DataSet UserLogin(string username, string userpass) { DataSet dsser = new DataSet(); NpgsqlConnection conn = new NpgsqlConnection(_dbConn); NpgsqlCommand command = new NpgsqlCommand("select id, userpassword as auth from info where username = '" + username + "' AND userpassword = '" + userpass + "';", conn); try { if (conn.State != ConnectionState.Open) { conn.Open(); } NpgsqlDataAdapter npgData = new NpgsqlDataAdapter(command); npgData.Fill(dsser, "Info"); UID = Convert.ToInt32(dsser.Tables["Info"].Rows[0]["id"]); AUTH = Convert.ToBoolean(dsser.Tables["Info"].Rows[0]["auth"]); } catch (NpgsqlException ex) { string msg = "FAILED -- "; msg += ex.Message; throw new Exception(msg); } finally { conn.Close(); } return dsser; } } }
The page i need to check the variables on has this code..
public partial class MainMenu : System.Web.UI.Page { DatabaseInterface dac = new DatabaseInterface(); protected void Page_Load(object sender, EventArgs e) { if (dac.AUTH) { } else { } } }
Then the login page where the method is called is like this
protected void btnLogin_Click(object sender, EventArgs e) { DataSet ds1 = dac.UserLogin(txtUser.Text, txtPassword.Text); if ((ds1 != null) && ds1.Tables[0].Rows.Count > 0) { DialogResult = true; this.Close(); } else { lblMessage.Content = "Login Failed! Try Again."; } }
Thats the stripped down version of the only 3 pages/files that have anything to do with this.
cubangt
Contributor
3052 Points
2402 Posts
Re: Trying to set property when executing authentication against DB but values are lost later in ...
Apr 23, 2012 02:47 AM|LINK
Here is my class file:
using System; using Npgsql; using System.Data; namespace DataAccess { class Class1 { private int _uid; private bool _auth; public int UID { get { return _uid; } set { _uid = value; } } public bool AUTH { get { return _auth; } set { _auth = value; } } private string _dbConn { get { return "Server=xxxxxxxx;Port=xxxxx;User Id=xxxxxx;Password=xxxxxx;Database=xxxxxxx;"; } } public DataSet UserLogin(string username, string userpass) { DataSet dsser = new DataSet(); NpgsqlConnection conn = new NpgsqlConnection(_dbConn); NpgsqlCommand command = new NpgsqlCommand("select id, userpassword as auth from info where username = '" + username + "' AND userpassword = '" + userpass + "';", conn); try { if (conn.State != ConnectionState.Open) { conn.Open(); } NpgsqlDataAdapter npgData = new NpgsqlDataAdapter(command); npgData.Fill(dsser, "Info"); UID = Convert.ToInt32(dsser.Tables["Info"].Rows[0]["id"]); AUTH = Convert.ToBoolean(dsser.Tables["Info"].Rows[0]["auth"]); } catch (NpgsqlException ex) { string msg = "FAILED -- "; msg += ex.Message; throw new Exception(msg); } finally { conn.Close(); } return dsser; } } }The page i need to check the variables on has this code..
public partial class MainMenu : System.Web.UI.Page { DatabaseInterface dac = new DatabaseInterface(); protected void Page_Load(object sender, EventArgs e) { if (dac.AUTH) { } else { } } }Then the login page where the method is called is like this
protected void btnLogin_Click(object sender, EventArgs e) { DataSet ds1 = dac.UserLogin(txtUser.Text, txtPassword.Text); if ((ds1 != null) && ds1.Tables[0].Rows.Count > 0) { DialogResult = true; this.Close(); } else { lblMessage.Content = "Login Failed! Try Again."; } }Thats the stripped down version of the only 3 pages/files that have anything to do with this.
---------------------
Mark as Answered if it helped