/// <summary> /// Main method of the user management console /// Called by 'Run()' and accepts two strings, one for the command, another for the arguments /// </summary> /// <param name="command"></param> /// <param name="args"></param> public static void Main(string command, string[] args) { if (command.ToLower() == "newuser") { UserMgmt.NewUser(); } else if (command.ToLower() == "switch") { UserMgmt.SwitchUsr(); } else if (command.ToLower() == "changepassword") { Environment_variables.current_usr.ChangePassword(); } else if (command.ToLower() == "list") { UserMgmt.ListUsers(); } else if (command == "") { } else { Console.WriteLine("Invalid command"); } }
/// <summary> /// Changes the user's password /// </summary> public void ChangePassword() { Console.Write("Insert new password:"******"Type password again:"); string passcheck = Console.ReadLine(); if (pass == passcheck) { string newpass = UserMgmt.GetHash(pass); this.pass = newpass; if (Environment_variables.current_usr == this) { Environment_variables.current_usr.pass = newpass; } //File.Delete(Vars.usr.userdir + User.passfile); File.WriteAllText(KernelVariables.homedir + Environment_variables.current_usr.passfile, newpass); Console.WriteLine("Password changed successfully!"); } else { Console.WriteLine("Passwords did not match!"); } }
/// <summary> /// Constructor for user, specifying username, full name and password /// </summary> /// <param name="username"></param> /// <param name="Name"></param> /// <param name="password"></param> public User(string username, string Name, string password) { this.username = username; this.Name = Name; pass = UserMgmt.GetHash(password); userdir = KernelVariables.homedir + @"\" + username; namefile = userdir + @"\name.sys"; usrfile = userdir + @"\user.sys"; passfile = userdir + @"\pass.sys"; if (Directory.Exists(userdir)) { Directory.Delete(userdir, true); } Directory.CreateDirectory(userdir); File.WriteAllText(usrfile, username); File.WriteAllText(namefile, Name); File.WriteAllText(passfile, pass); users.Add(this); }