public void ChangePAssword(long id, string newpassword, string oldpasssword) { SqlCommand cmd = con.GetSQLCommand(); Adminstrator admin = this.Get(id); //get admin by the id using function from this class if (admin.Password == oldpasssword) //check if the password and the string "oldpassword" matches { cmd.CommandText = $"UPDATE Administrator SET (PASSWORD='******') where ID = {admin.Id} ;"; cmd.ExecuteNonQuery(); } con.close(cmd); }
public Adminstrator Get(long id) { SqlCommand cmd = con.GetSQLCommand(); cmd.CommandText = $" SELECT * FROM Administrator WHERE ID ={id};"; Adminstrator admin = new Adminstrator(); SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.Default); while (reader.Read()) { admin.Id = (long)reader["Id"]; admin.UserName = (string)reader["USERNAME"]; admin.Password = (string)reader["PASSWORD"]; } con.close(cmd); return(admin); }
public IList <Adminstrator> GetAll() { SqlCommand cmd = con.GetSQLCommand(); cmd.CommandText = $" SELECT * FROM Administrator ;"; Adminstrator admin = new Adminstrator(); List <Adminstrator> list = new List <Adminstrator>(); SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.Default); while (reader.Read()) { admin.Id = (long)reader["Id"]; admin.UserName = (string)reader["USERNAME"]; admin.Password = (string)reader["PASSWORD"]; list.Add(admin); } con.close(cmd); return(list); }