private void btn_reg_with_card_Click(object sender, EventArgs e) { lbl_errors.Text = ""; // writeing reg user details to simple_user class// CardUser card_user = new CardUser(); card_user.Card_Number = txbx_regWithCard_cardNumber.Text; card_user.Email = txbx_regWithCard_email.Text; card_user.Password = txbx_regWithCard_password.Text; card_user.Confirm_Password = txbx_regWithCard_confirm_password.Text; card_user.CardUsedTime = DateTime.Now; // checking simple user texboxs if doesn't contain error user will be add to user database // CardUserValidator cardUser_val = new CardUserValidator(); if (cardUser_val.CheckInputs(card_user)) { string[] errors = cardUser_val.GetAllErrorArray(); foreach (string error in errors) { lbl_errors.Text += error + "\n"; } if (errors.Length == 0) { MessageBox.Show("Qeydiyyatınız uğurlu yekunlaşdı..."); UserDatabase.AddUser(card_user); UserLoginForm user_login_form = new UserLoginForm(); user_login_form.Show(); Visible = false; } } }
void ButtonAddUserClick(object sender, EventArgs e) { InputBoxValidation validation = delegate(string val) { if (val.Length < 4) { return("The username must contain at least 4 characters."); } if (UserDatabase.GetUserId(val) != -1) { return("The username already exists."); } return(""); }; string name = ""; var result = InputBox.Show("Add User", "Enter username (min. 4 characters):", ref name, validation); if (result == System.Windows.Forms.DialogResult.OK) { UserDatabase.AddUser(name, "1234567890"); FillComboUsers(); comboBoxUsers.SelectedIndex = comboBoxUsers.FindString(name); System.Windows.Forms.MessageBox.Show("User added.\nDon't forget to set a password and choose a home list.", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Information); ButtonChangePasswordClick(null, null); } }
public UserBasicDTO RegisterUser(UserDTO userDTO) { try { if (UserDBObject.UserNameExists(userDTO.UserName)) { throw new UserNameAlreadyExistsException(); } } catch (NotFoundException ex) { userDTO.PasswordHash = PasswordHasher.HashPassword(userDTO.Password); UserBasicDTO newUserBasicDTO = UserDBObject.AddUser(userDTO); return(newUserBasicDTO); } catch (UserNameAlreadyExistsException ex) { throw new UserNameAlreadyExistsException(); } catch (Exception ex) { throw new Exception(); } return(null); }
private void btn_reg_without_card_Click(object sender, EventArgs e) { lbl_errors.Text = ""; // writeing reg user details to simple_user class// SimpleUser simple_user = new SimpleUser(); simple_user.Name = txbx_reg_name.Text; simple_user.Surname = txbx_reg_surname.Text; simple_user.Email = txbx_reg_email.Text; simple_user.Password = txbx_reg_password.Text; simple_user.Confirm_Password = txbx_reg_confirm_password.Text; // checking simple user texboxs if doesn't contain error user will be add to user database// SimpleUserValidator simpleUser_val = new SimpleUserValidator(); if (simpleUser_val.CheckInputs(simple_user)) { string[] errors = simpleUser_val.GetAllErrorArray(); foreach (string error in errors) { lbl_errors.Text += error + "\n"; } if (errors.Length == 0) { MessageBox.Show("Qeydiyyatınız uğurlu yekunlaşdı." + "\n" + "Zəhmət olmasa sistemə daxil olun."); UserDatabase.AddUser(simple_user); UserLoginForm user_login_form = new UserLoginForm(); user_login_form.Show(); Visible = false; } } }
private void AddUserToDB(User user) { int newUserId = _userDB.AddUser(user); AssignSuperior(newUserId); _employees.Invalidate(); }
protected void RegisterUser(object sender, EventArgs e) { string username = txtUsername.Text; string password = txtPassword.Text; bool result = UserDatabase.AddUser(username, password); Server.Transfer("HomePage.aspx", true); }
public void AddUser( string name, PermissionLevel permissionLevel, [AllowSpaces] string favoriteFood) { if (UserDatabase.GetUserByName(name) != null) { Fail($"User {name} already exists!"); } UserDatabase.AddUser(name, favoriteFood, permissionLevel); Console.WriteLine($"Added user {name} with favorite food {favoriteFood}."); }
private async void RegisterUserCallback(Message message, TelegramBotClient bot, object arg) { try { UserDatabase.AddUser(service.Users.RegisterUserAsync(message.Chat.Id).Result); } catch (HttpRequestException ex) { await bot.SendTextMessageAsync(message.Chat.Id, $"Ошибка при регистрации пользователя: {ex.Message}", ParseMode.Markdown); return; } await CommandsCenter.GetMenu("StartMenu") .ShowAsync(message.Chat.Id, bot, $"Добро пожаловать в *мафию*..."); }
async void OnSignUpButtonClicked(object sender, EventArgs e) { var user = new User() { Username = usernameEntry.Text, Password = passwordEntry.Text, Email = emailEntry.Text }; userDB = new UserDatabase(); if (userDB.AddUser(user)) { await DisplayAlert("user added", "OK", "OK"); } else { await DisplayAlert("user not added", "OK", "OK"); } }
public UserBasicDTO RegisterUser(UserDTO userDTO) { try { if (userDatabase.UserEmailExists(userDTO.Email)) { throw new UserNameAlreadyExistsException(); } userDTO.HashPassword = PasswordHasher.HashPassword(userDTO.Password); UserBasicDTO userBasicDTO = userDatabase.AddUser(userDTO); return(userBasicDTO); } catch (UserNameAlreadyExistsException ex) { throw new UserNameAlreadyExistsException(); } catch (Exception ex) { throw new Exception(); } }
public void submit(object sender, EventArgs e) { // need to add test to see if any usernames are already taken in db // should add encryption string userName = txtUsername.Text; string password = txtPassword.Text; foreach (char c in userName) { if (!IsValid(c)) { userName = null; } } foreach (char c in password) { if (!IsValid(c)) { password = null; } } if (userName == null || password == null || txtUsername.Text.Length < 1 || txtPassword.Text.Length < 1) { errorLbl.Visible = true; errorLbl.Text = "Please enter the correct information"; } else { UserDatabase.AddUser(userName, password); Server.Transfer("HomePage.aspx", true); } }
public IndexModule() { Get["/"] = parameters => { dynamic model = new ExpandoObject(); model.loggedIn = Session["loggedIn"]; model.username = Session["username"]; return(View["index", model]); }; Get["/enable"] = parameters => { Session["para"] = "YES"; return("set."); }; Get["/disable"] = parameters => { Request.Session["para"] = "NO"; return("set."); }; Get["/what"] = _ => { string output = "KEY NOT FOUND"; try { output = Request.Session["para"].ToString(); } catch (Exception exc) { } return(output); System.Security.Cryptography.SHA256Managed c = new System.Security.Cryptography.SHA256Managed(); c.ComputeHash(System.Text.Encoding.UTF8.GetBytes("asdf"), 0, System.Text.Encoding.UTF8.GetByteCount("asdf")); }; Get["/count"] = _ => { try { Session["counter"] = (int)Session["counter"] + 1; } catch (Exception exc) { Session["counter"] = 1; } return(Session["counter"].ToString()); }; Get["/test"] = parameters => { string s = ""; foreach (var x in Session) { s += x + "<br />"; } return(s); return(Request.Session == Session ? "y" : "n"); }; //Get["/{whatever*}"] = _ => Response.AsRedirect("/"); Get["/(?:(?i)cv(\\.pdf)?)"] = _ => Response.AsFile("Content/cv.pdf"); Before.AddItemToEndOfPipeline(ctx => { Console.WriteLine("endofpipeline"); var sesh = ctx.Request.Session; if (sesh.Any(x => x.Key == "initialized")) { return(null); } Console.WriteLine("Setting session..."); sesh["initialized"] = true; sesh["username"] = "******"; sesh["loggedIn"] = false; return(null); }); Get["/users/exists/{usr}"] = ctx => UserDatabase.UserExists(ctx.usr) ? "true" : "false"; Post["/users/login"] = ctx => { var username = Request.Form.username.ToString(); var password = Request.Form.password.ToString(); System.Console.WriteLine(username); System.Console.WriteLine(password); if (!UserDatabase.UserExists(username)) { return("username not known."); } if (!UserDatabase.AttemptLogin(username, password)) { return("wrong password."); } Session["username"] = username; Session["loggedIn"] = true; return(Response.AsRedirect("/")); }; Post["/users/add"] = ctx => { var username = Request.Form.username.ToString(); var password = Request.Form.password.ToString(); System.Console.WriteLine(username); System.Console.WriteLine(password); if (UserDatabase.UserExists(username)) { return("username already exists."); } UserDatabase.AddUser(username, password); UserDatabase.AttemptLogin(username, password); Session["username"] = username; Session["loggedIn"] = true; return(Response.AsRedirect("/")); }; Post["/users/logout"] = _ => { Session["loggedIn"] = false; Session["username"] = "******"; return(Response.AsRedirect("/")); }; }
/// <summary> /// Updates user database. /// </summary> /// <param name="username">Users account username.</param> /// <param name="password">Users password.</param> /// <param name="certificateFilePath">Path on FS to users certificate.</param> /// <param name="usbKey">Set to true if user want to have an private USB key, otherwise it's set to false.</param> public void UpdateDatabase(ref string username, string password, string certificateFilePath, bool usbKey) { // Add a new user to Users.db. data.AddUser(username, password, File.ReadAllBytes(certificateFilePath), usbKey); }
private async void RegisterProcess_Clicked(object sender, EventArgs e) { RegisterMessage.TextColor = Color.LightGreen; RegisterMessage.Text = "Registration in progress..."; // Check if user has an internet connection. If there IS a connection, continue with the login process if (CheckNetwork.IsInternet()) { // Creating new user and setting Username and Password to the input from the login page var user = new User { Username = Entry_Username.Text, Password = Entry_Pass.Text, Nicename = Entry_Nicename.Text, Email = Entry_Email.Text, }; if (Entry_Username.Text != null && Entry_Pass.Text != null && Entry_ConfirmPass.Text != null && Entry_Email.Text != null && Entry_Nicename.Text != null) { indicator.IsVisible = true; if (Entry_Pass.Text == Entry_ConfirmPass.Text) { // Using hard coded admin to use it's bearer so we can register a user as this requires administrator access var userAuth = new User { Username = "******", Password = "******" }; // Login the administrator var authUser = await App.RestService.Login(userAuth); // Setting bearer to the accesstoken we received from the admin (Can't hardcode the token as it refreshes every so often) var bearer = authUser.AccessToken; Constants.CreateUserToken = bearer; if (user.Username.Length > 5) { if (Regex.Match(user.Username, @"^[a-zA-Z ]+$").Success) { if (user.Nicename.Length > 5) { if (Regex.Match(user.Nicename, @"^[a-zA-Z ]+$").Success) { // Check if user already exist by searing for it's username var doesUserExist = await App.RestService.DoesUserExist(user); if (doesUserExist) { RegisterMessage.TextColor = Color.Red; RegisterMessage.Text = "This username already exists. Please revise and try again."; } else { var userEmail = user.Email; var email = userEmail.ToLower(); var emailPattern = "^(?(\")(\".+?(?<!\\\\)\"@)|(([0-9a-z]((\\.(?!\\.))|[-!#\\$%&'\\*\\+/=\\?\\^`\\{\\}\\|~\\w])*)(?<=[0-9a-z])@))(?(\\[)(\\[(\\d{1,3}\\.){3}\\d{1,3}\\])|(([0-9a-z][-\\w]*[0-9a-z]*\\.)+[a-z0-9][\\-a-z0-9]{0,22}[a-z0-9]))$"; if (Regex.Match(email, emailPattern).Success) { // Sending the user's input to the register logic var registerResult = await App.RestService.Register(user); if (registerResult.WP_Id != 0) { RegisterMessage.TextColor = Color.LightGreen; RegisterMessage.Text = "Registration successfull. Logging you in."; var loginResult = await App.RestService.Login(user); UserDatabase uDB = new UserDatabase(); loginResult.Username = user.Username; loginResult.Password = user.Password; loginResult.Nickname = user.Nicename; loginResult.Email = user.Email; uDB.AddUser(loginResult); var AppUserData = uDB.GetAllUsers(); Console.WriteLine(AppUserData); await Task.Delay(1000); Navigation.InsertPageBefore(new Index(), this); await Navigation.PopAsync(); } } else { RegisterMessage.TextColor = Color.Red; RegisterMessage.Text = "Email is not in correct format. Please revise and try agian."; } } } else { RegisterMessage.TextColor = Color.Red; RegisterMessage.Text = "Full name must only contain letters. Please revise and try again."; } } else { RegisterMessage.TextColor = Color.Red; RegisterMessage.Text = "Full name must be at least 6 characters long. Please revise and try again."; } } else { RegisterMessage.TextColor = Color.Red; RegisterMessage.Text = "Username must only contain letters. Please revise and try again."; } } else { RegisterMessage.TextColor = Color.Red; RegisterMessage.Text = "Username must be at least 6 characters long. Please revise and try again."; } } else { RegisterMessage.TextColor = Color.Red; RegisterMessage.Text = "Password and Confirm password do not match. Please revise and try again."; } } else { RegisterMessage.TextColor = Color.Red; RegisterMessage.Text = "Not all fields were filled. Please revise and try again."; } } // If user does not have an internetconnection, return this error else { RegisterMessage.TextColor = Color.Red; RegisterMessage.Text = "You're not connected to the internet!"; } indicator.IsVisible = false; }
private bool Shell(bool superuser) { while (true) { string currentCommand = ""; Console.Write(AliasCurrentDir + prompt); string[] tokens = Console.ReadLine().Split(' '); currentCommand = tokens[0]; commandsChoice selectedCommand = commandsChoice.error; if (CommandCheck(tokens, currentCommand, ref selectedCommand, superuser) == false) { continue; } else { switch (selectedCommand) { case commandsChoice.logout: { return(false); } case commandsChoice.exit: { return(true); } case commandsChoice.clear: { Console.Clear(); break; //or continue } case commandsChoice.where: { Console.WriteLine(CurrentDir); break; } case commandsChoice.addUser: { UserDatabase db = new UserDatabase(@"C:\Users\Aleksa\source\repos\OOSWinSimpleShell\OOSWinSimpleShell\Users.db"); if (db.GetUser(tokens[1]) != null) { Console.WriteLine("Username '{0}' already exists.", tokens[1]); break; } Console.Write("Password:"******"C:\Users\Aleksa\source\repos\OOSWinSimpleShell\OOSWinSimpleShell\Users.db"); if (db.GetUser(tokens[1]) == null) { Console.WriteLine("User '{0}' doesn't exist.", tokens[1]); break; } Console.Write("sudo password: "******"root").IsPasswordValid(PasswordEnter())) { db.RemoveUser(tokens[1]); } else { Console.WriteLine("\nWrong sudo password."); } Console.WriteLine(); break; } case commandsChoice.go: { if (tokens[1].Equals("..")) { if (AliasCurrentDir == CurrentDir && CurrentDir.Contains("\\")) { AliasCurrentDir = CurrentDir = CurrentDir.Substring(0, CurrentDir.LastIndexOf("\\")); } else if (CurrentDir.Contains("\\")) { CurrentDir = CurrentDir.Substring(0, CurrentDir.LastIndexOf("\\")); } } else { tokens[1] = tokens[1].Trim(); if ((Directory.Exists(tokens[1]) && tokens[1].Contains("\\")) || Directory.Exists(CurrentDir + "\\" + tokens[1])) { if (AliasCurrentDir == CurrentDir && tokens[1].Contains("\\") && Directory.Exists(CurrentDir + "\\" + tokens[1])) { AliasCurrentDir = CurrentDir += "\\" + tokens[1]; } else if (AliasCurrentDir != CurrentDir && tokens[1].Contains("\\") && Directory.Exists(CurrentDir + "\\" + tokens[1])) { CurrentDir += "\\" + tokens[1]; } else if (AliasCurrentDir == CurrentDir && Directory.Exists(CurrentDir + "\\" + tokens[1])) { AliasCurrentDir = CurrentDir += "\\" + tokens[1]; } else if (AliasCurrentDir != CurrentDir && Directory.Exists(CurrentDir + "\\" + tokens[1])) { CurrentDir += "\\" + tokens[1]; } else if (AliasCurrentDir == CurrentDir && !Directory.Exists(CurrentDir + "\\" + tokens[1])) { AliasCurrentDir = CurrentDir = tokens[1]; } else { CurrentDir = tokens[1]; } } else { Console.WriteLine("Path is not valid."); } } break; } case commandsChoice.alias: { if (tokens.Length == 2) { AliasCurrentDir = tokens[1]; } else { AliasCurrentDir = CurrentDir; } break; } case commandsChoice.create: { string fileName = null; string path = null; SetFileNameAndPath(ref tokens, ref path, ref fileName); // help method Mkdir(fileName, path, tokens); break; } case commandsChoice.list: { if (tokens.Length == 2) { tokens[1] = tokens[1].Trim(); if (Directory.Exists(tokens[1])) { DirectorySearch(tokens[1], "\t"); } else { Console.WriteLine("Path is not valid."); } } else { DirectorySearch(CurrentDir, "\t"); } break; } case commandsChoice.findDat: { tokens[2] = tokens[2].Trim(); if (Directory.Exists(tokens[2])) { FindFile(tokens[2], tokens[1]); } else { Console.WriteLine("Path is not valid."); } break; } case commandsChoice.print: { if (File.Exists(CurrentDir + "\\" + tokens[1])) { string extension = Path.GetExtension(tokens[1]); if (extension == String.Empty) { Console.WriteLine("File {0} doesn't have extension information.", CurrentDir); } else if (extension.Contains(".")) { extension = extension.TrimStart('.'); if (extension.Equals("txt")) { Console.Write(File.ReadAllText(CurrentDir + "\\" + tokens[1])); } else { Console.WriteLine("File '{0}' is not a text file.", CurrentDir + tokens[1]); } } else { Console.WriteLine("File doesn't have an extension."); } } else { Console.WriteLine("File '{0}' doesn't exist in path {1}.", tokens[1], CurrentDir); } break; } case commandsChoice.find: { if (tokens[1].StartsWith("\"") && tokens[1].EndsWith("\"") && tokens[1].Length > 2) { if (File.Exists(CurrentDir + "\\" + tokens[2])) { tokens[1] = tokens[1].Substring(1, tokens[1].Length - 2); var lines = File.ReadLines(CurrentDir + "\\" + tokens[2]); int lineNmb = 1; foreach (var line in lines) { if (line.Contains(tokens[1])) { Console.Write(lineNmb + ":"); Console.Write(line.Substring(0, line.IndexOf(tokens[1]))); Console.ForegroundColor = ConsoleColor.Red; Console.Write(tokens[1]); Console.ResetColor(); Console.WriteLine(line.Substring(line.IndexOf(tokens[1]) + tokens[1].Length)); break; } lineNmb++; } } else { Console.WriteLine("File '{0}' doesn't exist in path {1}.", tokens[2], CurrentDir); } } else { Console.WriteLine("Text option doesn't have the correct signature."); } break; } } } } }
// LoginProcess, this is being called from the Login button on the login page private async void LoginProcess_Clicked(object sender, EventArgs e) { indicator.IsVisible = true; // Check if user has an internet connection. If there IS a connection, continue with the login process if (CheckNetwork.IsInternet()) { // Creating new user and setting Username and Password to the input from the login page var user = new User { Username = Entry_Username.Text, Password = Entry_Pass.Text }; // Check if input fields are empty and display error in LoginMessage label if a field, or both, are empty if (user.Username == "" || user.Password == "") { LoginMessage.TextColor = Color.Red; LoginMessage.Text = "Username or password field is empty"; } // If all fields are filled continue and display "Loggin in! Please wait..." in the LoginMessage label on the loginpage else { LoginMessage.TextColor = Color.SpringGreen; LoginMessage.Text = "Logging in! Please wait..."; var result = await App.RestService.Login(user); var dbclear = new UserDatabase(); dbclear.Droptable(); // Check if you get an AccessToken from the local database. (One will be stored there with the user if login is successful) // If an accesstoken exists in the local database, continue with the login if (result.AccessToken != null) { // Setting user info to result info from login user.Id = result.Id; result.Username = user.Username; result.Password = user.Password; user.Nicename = result.Displayname; user.Email = result.Email; var userDatabase = new UserDatabase(); userDatabase.AddUser(result); //userDatabase.UpdateUser(result); LoginMessage.Text = ""; Entry_Pass.Text = ""; LoginMessage.Text = "Logged in!"; await Task.Delay(1000); Navigation.InsertPageBefore(new Index(), this); await Navigation.PopAsync(); } // If no accesstoken was found, the user wasn't logged in due to invalid login info and an error is returned to the loginpage else { LoginMessage.TextColor = Color.Red; LoginMessage.Text = "Invalid login information... Please try again!"; } } } // If user does not have an internetconnection, return this error else { LoginMessage.TextColor = Color.Red; LoginMessage.Text = "You're not connected to the internet!"; } indicator.IsVisible = false; }