public ApiResult <bool> ChangePassword(RequestPassword model) { IUser user; switch (model.Type) { case 0: user = ApplicationUser.FindByName(model.UserName); CheckUser(user); if (user.Password != model.OldPassword.MD5()) { throw ApiException.Common(RequestLocalizer["The old password is incorrect"]); } break; case 1: user = ApplicationUser.FindByMobile(model.Mobile); CheckUser(user); if (!CheckVerCode(model.InternationalAreaCode + model.Mobile, model.VerCode, 0)) { throw ApiException.Common(RequestLocalizer["The verification code is incorrect or expired"]); } if (user.Mobile != model.Mobile) { throw ApiException.Common(RequestLocalizer["Incorrect mobile phone number"]); } break; case 2: user = ApplicationUser.FindByMail(model.Mail); CheckUser(user); if (!CheckVerCode(model.Mail, model.VerCode, 1)) { throw ApiException.Common(RequestLocalizer["The verification code is incorrect or expired"]); } if (user.Mail != model.Mail) { throw ApiException.Common(RequestLocalizer["Incorrect email address"]); } break; default: throw ApiException.Common("Type类型不正确!"); } void CheckUser(IUser u) { if (u == null) { throw ApiException.Common(RequestLocalizer["The user was not found"]); } } user.Password = model.NewPassword; user.Save(); return(ApiResult.Ok(true)); }
public static string RequestPassphrase(ServerConfig conf) { RequestPassword req = new RequestPassword(2, conf.Hostname, conf.Username); req.ShowDialog(); string password = req.password; req.Close(); return(password); }
public AuthenticationPrompt KnowsUserPassword(bool previousTrySuccess) { return(RequestPassword.KnowsUserPassword(previousTrySuccess)); }
private static void Main() { // Set the type to be reflected. AssemblyInfo.Assembly = System.Reflection.Assembly.GetAssembly(typeof(Program)); Log.Info(String.Format("-------------------------------{0} started. Version: {1}, Date: {2}-------------------------------", AssemblyInfo.Title, AssemblyInfo.Version, AssemblyInfo.BuildDate)); string[] cmdLineArgs = Environment.GetCommandLineArgs(); #region Command line // Check if we need to display the help screen. if (Parser.ParseHelp(cmdLineArgs)) { Log.Info("Showing Terminals in command line mode."); string helpText = Parser.ArgumentsUsage(typeof(CommandLineArgs)); // Attach to an parent process console if (!AttachConsole(-1)) { // Alloc a new console AllocConsole(); } const ConsoleColor headerBackground = ConsoleColor.Blue; int maxLen = 0; if (AssemblyInfo.TitleVersion.Count() >= AssemblyInfo.Url.Count() && AssemblyInfo.TitleVersion.Count() >= AssemblyInfo.Author.Count()) { maxLen = AssemblyInfo.TitleVersion.Count(); } if (AssemblyInfo.Author.Count() >= AssemblyInfo.Url.Count() && AssemblyInfo.Author.Count() >= AssemblyInfo.TitleVersion.Count()) { maxLen = AssemblyInfo.Author.Count(); } if (AssemblyInfo.Url.Count() >= AssemblyInfo.TitleVersion.Count() && AssemblyInfo.Url.Count() >= AssemblyInfo.Author.Count()) { maxLen = AssemblyInfo.Url.Count(); } // * * * Set the program name * * * ConsoleColor backgroundColor = Console.BackgroundColor; ConsoleColor foregroundColor = Console.ForegroundColor; Console.Write(Environment.NewLine + Environment.NewLine + " "); Console.BackgroundColor = headerBackground; // +2 -> one ' ' before the text and one after for (int i = 0; i < maxLen + 2; i++) { Console.Write(" "); } Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; Console.Write(Environment.NewLine + " "); Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = headerBackground; Console.Write(" "); Console.Write(AssemblyInfo.TitleVersion.PadRight(maxLen + 1)); Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; // * * * Set the line * * * Console.Write(Environment.NewLine + " "); string t = null; for (int i = 0; i < AssemblyInfo.TitleVersion.Count(); i++) { t += "═"; } Console.ForegroundColor = ConsoleColor.Cyan; Console.BackgroundColor = headerBackground; Console.Write(" "); Console.Write(t.PadRight(maxLen + 1)); Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; Console.Write(Environment.NewLine + " "); Console.BackgroundColor = headerBackground; // +2 -> one ' ' before the text and one after for (int i = 0; i < maxLen + 2; i++) { Console.Write(" "); } // * * * Set the author * * * Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; Console.Write(Environment.NewLine + " "); Console.ForegroundColor = ConsoleColor.Yellow; Console.BackgroundColor = headerBackground; Console.Write(" "); Console.Write(AssemblyInfo.Author.PadRight(maxLen + 1)); Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; // * * * Set the url * * * Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; Console.Write(Environment.NewLine + " "); Console.BackgroundColor = headerBackground; Console.Write(" "); Console.ForegroundColor = ConsoleColor.Magenta; Console.BackgroundColor = ConsoleColor.White; Console.Write(AssemblyInfo.Url); Console.BackgroundColor = headerBackground; Console.Write(" "); Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; Console.Write(Environment.NewLine + " "); Console.BackgroundColor = headerBackground; // +2 -> one ' ' before the text and one after for (int i = 0; i < maxLen + 2; i++) { Console.Write(" "); } Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; // * * * Add the rest of the text * * * Console.Write(Environment.NewLine + Environment.NewLine + helpText + Environment.NewLine + Environment.NewLine); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("Press any key to continue . . ."); Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; Console.Write(" "); LogTerminalsStopped(); return; } #endregion // Set application behaviour -> this must occur before the first UI creation events! Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); CommandLineArgs commandLine = ParseCommandline(cmdLineArgs); // Create a backup of the current Terminals.config file CreateConfigFileBackup(); // This won't force the configuration to get invalid -> parsing will occur later. if (Settings.IsMasterPasswordDefined) { using (RequestPassword requestPassword = new RequestPassword()) { // If the password has been entered three times wrong or the user has clicked the cancel button -> // Return from the main procedure. - Application.Exit() will not work here! if (requestPassword.ShowDialog() != DialogResult.OK) { return; } } } // Upgrade the configuration file if necessary //UpdateConfig.CheckConfigVersionUpdate(); Application.ThreadException += Application_ThreadException; // Create the main form. mainForm = new MainForm(); if (UserAccountControlNotSatisfied()) { LogTerminalsStopped(); return; } if (commandLine.SingleInstance && SingleInstanceApplication.Instance.NotifyExisting(commandLine)) { LogTerminalsStopped(); return; } // UpdateManager.CheckForUpdates(commandLine); // Log the company name, current windows user, machine domain, etc. LogGeneralProperties(); // Start the main form and wait for it to return. StartMainForm(commandLine); LogTerminalsStopped(); }
protected virtual void OnRequestPassword(PasswordEventArgs e) { RequestPassword?.Invoke(this, e); }
private void OnRequestPassword(BaseMessage <RequestPasswordInfo> pInfo) { RequestPassword?.Invoke(pInfo); }
private static void Main() { // Set the type to be reflected. AssemblyInfo.Assembly = System.Reflection.Assembly.GetAssembly(typeof(Program)); Log.Info(String.Format("-------------------------------{0} started. Version: {1}, Date: {2}-------------------------------", AssemblyInfo.Title, AssemblyInfo.Version, AssemblyInfo.BuildDate)); string[] cmdLineArgs = Environment.GetCommandLineArgs(); #region Command line // Check if we need to display the help screen. if (Parser.ParseHelp(cmdLineArgs)) { Log.Info("Showing Terminals in command line mode."); string helpText = Parser.ArgumentsUsage(typeof(CommandLineArgs)); // Attach to an parent process console if (!AttachConsole(-1)) { // Alloc a new console AllocConsole(); } const ConsoleColor headerBackground = ConsoleColor.Blue; int maxLen = 0; if (AssemblyInfo.TitleVersion.Count() >= AssemblyInfo.Url.Count() && AssemblyInfo.TitleVersion.Count() >= AssemblyInfo.Author.Count()) { maxLen = AssemblyInfo.TitleVersion.Count(); } if (AssemblyInfo.Author.Count() >= AssemblyInfo.Url.Count() && AssemblyInfo.Author.Count() >= AssemblyInfo.TitleVersion.Count()) { maxLen = AssemblyInfo.Author.Count(); } if (AssemblyInfo.Url.Count() >= AssemblyInfo.TitleVersion.Count() && AssemblyInfo.Url.Count() >= AssemblyInfo.Author.Count()) { maxLen = AssemblyInfo.Url.Count(); } // * * * Set the program name * * * ConsoleColor backgroundColor = Console.BackgroundColor; ConsoleColor foregroundColor = Console.ForegroundColor; Console.Write(Environment.NewLine + Environment.NewLine + " "); Console.BackgroundColor = headerBackground; // +2 -> one ' ' before the text and one after for (int i = 0; i < maxLen + 2; i++) { Console.Write(" "); } Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; Console.Write(Environment.NewLine + " "); Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = headerBackground; Console.Write(" "); Console.Write(AssemblyInfo.TitleVersion.PadRight(maxLen + 1)); Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; // * * * Set the line * * * Console.Write(Environment.NewLine + " "); string t = null; for (int i = 0; i < AssemblyInfo.TitleVersion.Count(); i++) t += "═"; Console.ForegroundColor = ConsoleColor.Cyan; Console.BackgroundColor = headerBackground; Console.Write(" "); Console.Write(t.PadRight(maxLen + 1)); Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; Console.Write(Environment.NewLine + " "); Console.BackgroundColor = headerBackground; // +2 -> one ' ' before the text and one after for (int i = 0; i < maxLen + 2; i++) { Console.Write(" "); } // * * * Set the author * * * Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; Console.Write(Environment.NewLine + " "); Console.ForegroundColor = ConsoleColor.Yellow; Console.BackgroundColor = headerBackground; Console.Write(" "); Console.Write(AssemblyInfo.Author.PadRight(maxLen + 1)); Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; // * * * Set the url * * * Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; Console.Write(Environment.NewLine + " "); Console.BackgroundColor = headerBackground; Console.Write(" "); Console.ForegroundColor = ConsoleColor.Magenta; Console.BackgroundColor = ConsoleColor.White; Console.Write(AssemblyInfo.Url); Console.BackgroundColor = headerBackground; Console.Write(" "); Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; Console.Write(Environment.NewLine + " "); Console.BackgroundColor = headerBackground; // +2 -> one ' ' before the text and one after for (int i = 0; i < maxLen + 2; i++) { Console.Write(" "); } Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; // * * * Add the rest of the text * * * Console.Write(Environment.NewLine + Environment.NewLine + helpText + Environment.NewLine + Environment.NewLine); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("Press any key to continue . . ."); Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; Console.Write(" "); LogTerminalsStopped(); return; } #endregion // Set application behaviour -> this must occur before the first UI creation events! Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); CommandLineArgs commandLine = ParseCommandline(cmdLineArgs); // Create a backup of the current Terminals.config file CreateConfigFileBackup(); // This won't force the configuration to get invalid -> parsing will occur later. if (Settings.IsMasterPasswordDefined) { using (RequestPassword requestPassword = new RequestPassword()) { // If the password has been entered three times wrong or the user has clicked the cancel button -> // Return from the main procedure. - Application.Exit() will not work here! if (requestPassword.ShowDialog() != DialogResult.OK) return; } } // Upgrade the configuration file if necessary //UpdateConfig.CheckConfigVersionUpdate(); Application.ThreadException += Application_ThreadException; // Create the main form. mainForm = new MainForm(); if (UserAccountControlNotSatisfied()) { LogTerminalsStopped(); return; } if (commandLine.SingleInstance && SingleInstanceApplication.Instance.NotifyExisting(commandLine)) { LogTerminalsStopped(); return; } // UpdateManager.CheckForUpdates(commandLine); // Log the company name, current windows user, machine domain, etc. LogGeneralProperties(); // Start the main form and wait for it to return. StartMainForm(commandLine); LogTerminalsStopped(); }