コード例 #1
0
 private object logIn(IDictionary <string, object> input)
 {
     /*if (input.ContainsKey("account"))
      * {
      *  var Accounts = Instance.GetAccountsForCurrentSite();
      *  foreach (var x in Accounts)
      *  {
      *      if (x.AccountName== (string)input["account"])
      *      {
      *          Instance.Login(x);
      *          return true;
      *      }
      *  }
      * }
      * else*/
     {
         List <BaseSite.LoginParamValue> Value = new List <BaseSite.LoginParamValue>();
         foreach (var x in Instance.CurrentSite.LoginParams)
         {
             Value.Add(new BaseSite.LoginParamValue {
                 Param = x, Value = (string)input[x.Name.Replace(" ", "_")]
             });
         }
         Instance.Login(Value.ToArray());
         return(true);
     }
     return(false);
 }
コード例 #2
0
ファイル: ConsoleUI.cs プロジェクト: WildMachine/DoormatBot
        void Login()
        {
            if (DiceBot.CurrentSite == null || DiceBot.LoggedIn)
            {
                Console.WriteLine("Invalid state for this command.");
                return;
            }
            string keepasspw       = "";
            string keepassnote     = "";
            string keepassusername = "";

            if (DiceBot.KeepassOpen)
            {
                Console.Write("Log in using a KeePass Account? (1: Yes; 2: No;): ");
                string res = Console.ReadLine().ToLower();
                if (res == "1" && res == "yes")
                {
                    KPHelper[] kPHelpers = DiceBot.GetAccounts();
                    int        i         = 0;
                    Console.WriteLine(string.Format("{0}{1}{2}", "".PadRight(5), "Title".PadRight(30), "Username".PadRight(30), "URL".PadRight(30)));
                    foreach (KPHelper x in kPHelpers)
                    {
                        Console.WriteLine(string.Format("{0}{1}{2}{3}", (i++ + ")").PadRight(5), x.Title.PadRight(30), x.Username.PadRight(30), x.URL.PadRight(30)));
                    }
                    Console.WriteLine("Enter account number to user: "******"";
                    int result = -1;
                    while (res.ToLower() != "cancel" && res.ToLower() != "back" && int.TryParse(res, out result))
                    {
                        res = Console.ReadLine();
                    }
                    if (result >= 0)
                    {
                        keepassnote     = "";
                        keepassusername = kPHelpers[result].Username;
                        keepasspw       = DiceBot.GetPw(kPHelpers[result], out keepassnote);
                    }
                }
            }
            List <DoormatCore.Sites.BaseSite.LoginParamValue> LoginVals = new List <DoormatCore.Sites.BaseSite.LoginParamValue>();
            int counter = 0;

            foreach (DoormatCore.Sites.BaseSite.LoginParameter x in DiceBot.CurrentSite.LoginParams)
            {
                string Result = "";
                if (!x.Masked && !string.IsNullOrWhiteSpace(keepassusername) && counter == 0)
                {
                    Result = keepassusername;
                }
                else if (x.Masked && !string.IsNullOrWhiteSpace(keepasspw) && (counter == 0 || counter == 1))
                {
                    Result = keepasspw;
                }
                else if (x.Masked && !string.IsNullOrWhiteSpace(keepassnote) && (counter == 2))
                {
                    Result = keepassnote;
                }
                if (Result == "")
                {
                    do
                    {
                        Console.Write(x.Name + ": ");

                        if (x.Masked)
                        {
                            string         pass = "";
                            ConsoleKeyInfo key;
                            do
                            {
                                key = Console.ReadKey(true);

                                if (key.Key != ConsoleKey.Backspace)
                                {
                                    pass += key.KeyChar;
                                    Console.Write("*");
                                }
                                else
                                {
                                    pass = pass.Substring(0, (pass.Length - 1));
                                    Console.Write("\b \b");
                                }
                            }
                            // Stops Receving Keys Once Enter is Pressed
                            while (key.Key != ConsoleKey.Enter);
                            foreach (char y in pass)
                            {
                                Console.Write("\b \b");
                            }
                            if (pass.EndsWith("\r"))
                            {
                                pass = pass.Replace("\r", "");
                            }
                            Result = pass;
                            Console.WriteLine();
                        }
                        else
                        {
                            Result = Console.ReadLine();
                        }
                    } while (string.IsNullOrEmpty(Result) && x.Required);
                }
                LoginVals.Add(new DoormatCore.Sites.BaseSite.LoginParamValue {
                    Param = x, Value = Result
                });
            }
            DiceBot.OnSiteLoginFinished -= CurrentSite_LoginFinished;
            DiceBot.OnSiteLoginFinished += CurrentSite_LoginFinished;
            Console.WriteLine("Logging in...");
            DiceBot.Login(LoginVals.ToArray());
        }