public static void Create_user() { while (true) { Console.WriteLine("\n\n\n Please insert the credentials for the new user"); Console.Write(" Username : "******" Password : "******"SELECT [username] FROM [ChatDB].[dbo].[Users] where [username] ='" + un + "'"; string insertqs = "insert into[ChatDB].[dbo].[Users] (username,password,role) values('" + un + "','" + ps + "',0)"; List <string> resultlist = new List <string>(); resultlist = Database_access.queryDB(qs); if (resultlist.Count() > 0) { Console.WriteLine("User already exists, please select another user"); } else { Database_access.updateDB(insertqs); Console.WriteLine("User Succesfully created"); break; } } }
public static List <string> get_users() { string qs = "SELECT [username] FROM [ChatDB].[dbo].[Users]"; List <string> resultlist = new List <string>(); resultlist = Database_access.queryDB(qs); return(resultlist); }
public static void show_users() { string qs = "SELECT [username] FROM [ChatDB].[dbo].[Users]"; List <string> resultlist = new List <string>(); resultlist = Database_access.queryDB(qs); Console.WriteLine("\n\n --- Edit Users ---\n\n"); for (int i = 0; i < resultlist.Count(); i++) { Console.WriteLine("\n" + i + ". " + resultlist[i] + "\n"); } }
public static bool validate_user(string user) // checks in the DB is the username/ password is acceptable and returns role { string qs = "SELECT [username] FROM [ChatDB].[dbo].[Users] where [username]='" + user + "'"; List <string> rolelist = new List <string>(); rolelist = Database_access.queryDB(qs); if (rolelist.Count() == 0) { return(false); } else { return(true); } }
public static int validate_user(string user, string pass) // checks in the DB is the username/ password is acceptable and returns role { if ((user == "admin") && (pass == "admin")) { return(-1); } else { string qs = "SELECT [role] FROM [ChatDB].[dbo].[Users] where [username]='" + user + "' and [password]='" + pass + "'"; List <string> rolelist = new List <string>(); rolelist = Database_access.queryDB(qs); if (rolelist.Count() == 0) { return(-2); } else { int n = int.Parse(rolelist[0]); return(n); } } }