public static bool UpdatePassword(LoReUp user, string newpassword) { if (user != null) { MySqlConnection conn = new MySqlConnection(Connection.user); conn.Open(); string Query = $@"UPDATE users SET password='******' WHERE username='******';"; MySqlCommand command = new MySqlCommand(Query, conn); command.ExecuteNonQuery(); conn.Close(); return(true); } return(false); }
protected void Registerbot_Click(object sender, EventArgs e) { string username = UsernameR.Text; string password = PasswordR.Text; if (LoReUp.IfUserExit(username) == false) { LoReUp.Register(username, password); ResultLabel.Text = "Registered successfully"; } else { ResultLabel.Text = "User Already exist"; } }
protected void Loginbot_Click(object sender, EventArgs e) { string username = UsernameL.Text; string password = PasswordL.Text; LoReUp newuser = LoReUp.Login(username, password); if (newuser != null) { Session["user"] = newuser; Response.Redirect("HomePage.aspx"); ResultLabel.Text = "Loged"; } else { ResultLabel.Text = "Wrong username or password"; } }
public static LoReUp Login(string username, string password) { MySqlConnection conn = new MySqlConnection(Connection.user); conn.Open(); string Query = $@"select id,username,password from users where username='******' and password='******';"; MySqlCommand command = new MySqlCommand(Query, conn); LoReUp user = null; MySqlDataReader dr = command.ExecuteReader(); if (dr.Read()) { string name = dr.GetString(1); string pass = dr.GetString(2); user = new LoReUp(name, pass); } conn.Close(); return(user); }