}
}
- public Grid this [int ix]
+ public Grid this[int ix]
{
get { return Grids[ix]; }
}
+ public Grid this[string gridID]
+ {
+ get
+ {
+ foreach (Grid grid in Grids)
+ {
+ if (grid.ID == gridID) return grid;
+ }
+ throw new KeyNotFoundException();
+ }
+ }
+
+ public bool KeyExists(string gridID)
+ {
+ foreach (Grid grid in Grids)
+ {
+ if (grid.ID == gridID) return true;
+ }
+ return false;
+ }
+
public int Count
{
get { return Grids.Count; }
private void InitializeComponent()
{
this.pnlLoginPrompt = new System.Windows.Forms.Panel();
+ this.cbRemember = new System.Windows.Forms.CheckBox();
this.label6 = new System.Windows.Forms.Label();
this.txtCustomLoginUri = new System.Windows.Forms.TextBox();
this.cbxGrid = new System.Windows.Forms.ComboBox();
this.label5 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
- this.txtUsername = new System.Windows.Forms.TextBox();
+ this.cbxUsername = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.txtPassword = new System.Windows.Forms.TextBox();
this.cbxLocation = new System.Windows.Forms.ComboBox();
this.proLogin = new System.Windows.Forms.ProgressBar();
this.lblLoginStatus = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
- this.btnGridManager = new System.Windows.Forms.Button();
this.lblVersion = new System.Windows.Forms.Label();
this.pnlSplash = new System.Windows.Forms.Panel();
this.pnlTos = new System.Windows.Forms.Panel();
this.cbTOS = new System.Windows.Forms.CheckBox();
this.txtTOS = new System.Windows.Forms.TextBox();
- this.cbRemember = new System.Windows.Forms.CheckBox();
this.pnlLoginPrompt.SuspendLayout();
this.pnlLoggingIn.SuspendLayout();
this.panel1.SuspendLayout();
this.pnlLoginPrompt.Controls.Add(this.cbxGrid);
this.pnlLoginPrompt.Controls.Add(this.label5);
this.pnlLoginPrompt.Controls.Add(this.label1);
- this.pnlLoginPrompt.Controls.Add(this.txtUsername);
+ this.pnlLoginPrompt.Controls.Add(this.cbxUsername);
this.pnlLoginPrompt.Controls.Add(this.label2);
this.pnlLoginPrompt.Controls.Add(this.txtPassword);
this.pnlLoginPrompt.Controls.Add(this.cbxLocation);
this.pnlLoginPrompt.Size = new System.Drawing.Size(554, 94);
this.pnlLoginPrompt.TabIndex = 13;
//
+ // cbRemember
+ //
+ this.cbRemember.AutoSize = true;
+ this.cbRemember.Checked = true;
+ this.cbRemember.CheckState = System.Windows.Forms.CheckState.Checked;
+ this.cbRemember.Location = new System.Drawing.Point(6, 45);
+ this.cbRemember.Name = "cbRemember";
+ this.cbRemember.Size = new System.Drawing.Size(197, 17);
+ this.cbRemember.TabIndex = 5;
+ this.cbRemember.Text = "Remember username and password";
+ this.cbRemember.UseVisualStyleBackColor = true;
+ this.cbRemember.CheckedChanged += new System.EventHandler(this.cbRemember_CheckedChanged);
+ //
// label6
//
this.label6.AutoSize = true;
this.label1.TabIndex = 0;
this.label1.Text = "Username";
//
- // txtUsername
+ // cbxUsername
//
- this.txtUsername.AccessibleName = "Username";
- this.txtUsername.Location = new System.Drawing.Point(3, 16);
- this.txtUsername.Name = "txtUsername";
- this.txtUsername.Size = new System.Drawing.Size(263, 21);
- this.txtUsername.TabIndex = 1;
+ this.cbxUsername.AccessibleName = "Username";
+ this.cbxUsername.Location = new System.Drawing.Point(3, 16);
+ this.cbxUsername.Name = "cbxUsername";
+ this.cbxUsername.Size = new System.Drawing.Size(263, 21);
+ this.cbxUsername.TabIndex = 1;
//
// label2
//
this.txtPassword.Size = new System.Drawing.Size(275, 21);
this.txtPassword.TabIndex = 4;
this.txtPassword.UseSystemPasswordChar = true;
- this.txtPassword.TextChanged += new System.EventHandler(this.txtPassword_TextChanged);
//
// cbxLocation
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.Control;
- this.panel1.Controls.Add(this.btnGridManager);
this.panel1.Controls.Add(this.lblVersion);
this.panel1.Controls.Add(this.pnlLoginPrompt);
this.panel1.Controls.Add(this.btnLogin);
this.panel1.Size = new System.Drawing.Size(682, 97);
this.panel1.TabIndex = 18;
//
- // btnGridManager
- //
- this.btnGridManager.ForeColor = System.Drawing.SystemColors.ControlText;
- this.btnGridManager.Location = new System.Drawing.Point(6, 44);
- this.btnGridManager.Name = "btnGridManager";
- this.btnGridManager.Size = new System.Drawing.Size(116, 23);
- this.btnGridManager.TabIndex = 16;
- this.btnGridManager.Text = "Grid Manager";
- this.btnGridManager.UseVisualStyleBackColor = true;
- this.btnGridManager.Visible = false;
- //
// lblVersion
//
this.lblVersion.AutoSize = true;
this.txtTOS.Size = new System.Drawing.Size(682, 302);
this.txtTOS.TabIndex = 0;
//
- // cbRemember
- //
- this.cbRemember.AutoSize = true;
- this.cbRemember.Checked = true;
- this.cbRemember.CheckState = System.Windows.Forms.CheckState.Checked;
- this.cbRemember.Location = new System.Drawing.Point(6, 45);
- this.cbRemember.Name = "cbRemember";
- this.cbRemember.Size = new System.Drawing.Size(197, 17);
- this.cbRemember.TabIndex = 5;
- this.cbRemember.Text = "Remember username and password";
- this.cbRemember.UseVisualStyleBackColor = true;
- this.cbRemember.CheckedChanged += new System.EventHandler(this.cbRemember_CheckedChanged);
- //
// LoginConsole
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
public System.Windows.Forms.Panel pnlLoginPrompt;
public System.Windows.Forms.Label label1;
- public System.Windows.Forms.TextBox txtUsername;
+ public System.Windows.Forms.ComboBox cbxUsername;
public System.Windows.Forms.Label label2;
public System.Windows.Forms.TextBox txtPassword;
public System.Windows.Forms.ComboBox cbxLocation;
public System.Windows.Forms.Label label6;
public System.Windows.Forms.Panel panel1;
public System.Windows.Forms.Panel pnlSplash;
- public System.Windows.Forms.Button btnGridManager;
public System.Windows.Forms.Panel pnlTos;
public System.Windows.Forms.TextBox txtTOS;
public System.Windows.Forms.CheckBox cbTOS;
panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(210)))), ((int)(((byte)(210)))), ((int)(((byte)(225)))));
cbxLocation.SelectedIndex = 0;
+ cbxUsername.SelectedIndexChanged += cbxUsername_SelectedIndexChanged;
InitializeConfig();
}
if (cbRemember.Checked)
{
- s["username"] = txtUsername.Text;
+ SavedLogin sl = new SavedLogin();
- if (netcom.LoginOptions.IsPasswordMD5)
- s["password"] = OSD.FromString(txtPassword.Text);
+ string username = cbxUsername.Text;
+
+ if (cbxUsername.SelectedIndex > 0 && cbxUsername.SelectedItem is SavedLogin)
+ {
+ username = ((SavedLogin)cbxUsername.SelectedItem).Username;
+ }
+
+ sl.Username = s["username"] = username;
+
+ if (LoginOptions.IsPasswordMD5(txtPassword.Text))
+ {
+ sl.Password = txtPassword.Text;
+ s["password"] = txtPassword.Text;
+ }
+ else
+ {
+ sl.Password =Utils.MD5(txtPassword.Text);
+ s["password"] = Utils.MD5(txtPassword.Text);
+ }
+
+ if (cbxGrid.SelectedIndex == cbxGrid.Items.Count - 1) // custom login uri
+ {
+ sl.GridID = "custom_login_uri";
+ sl.CustomURI = txtCustomLoginUri.Text;
+ }
else
- s["password"] = OSD.FromString(Utils.MD5(txtPassword.Text));
+ {
+ sl.GridID = (cbxGrid.SelectedItem as Grid).ID;
+ sl.CustomURI = string.Empty;
+ }
+ if (!(s["saved_logins"] is OSDMap))
+ {
+ s["saved_logins"] = new OSDMap();
+ }
+ ((OSDMap)s["saved_logins"])[string.Format("{0}%{1}", sl.Username, sl.GridID)] = sl.ToOSD();
}
s["login_location_type"] = OSD.FromInteger(cbxLocation.SelectedIndex);
Settings s = instance.GlobalSettings;
// Setup login name
+ string savedUsername;
+
if (string.IsNullOrEmpty(MainProgram.CommandLine.Username))
{
- txtUsername.Text = s["username"];
+ savedUsername = s["username"];
}
else
{
- txtUsername.Text = MainProgram.CommandLine.Username;
+ savedUsername = MainProgram.CommandLine.Username;
}
+ cbxUsername.Items.Add(savedUsername);
+
+ try
+ {
+ if (s["saved_logins"] is OSDMap)
+ {
+ OSDMap savedLogins = (OSDMap)s["saved_logins"];
+ foreach (string loginKey in savedLogins.Keys)
+ {
+ SavedLogin sl = SavedLogin.FromOSD(savedLogins[loginKey]);
+ cbxUsername.Items.Add(sl);
+ }
+ }
+ }
+ catch
+ {
+ cbxUsername.Items.Clear();
+ cbxUsername.Text = string.Empty;
+ }
+
+ cbxUsername.SelectedIndex = 0;
// Fill in saved password or use one specified on the command line
if (string.IsNullOrEmpty(MainProgram.CommandLine.Password))
{
txtPassword.Text = s["password"].AsString();
- netcom.LoginOptions.IsPasswordMD5 = true;
}
else
{
txtPassword.Text = MainProgram.CommandLine.Password;
- netcom.LoginOptions.IsPasswordMD5 = false;
}
private void BeginLogin()
{
- var parts = System.Text.RegularExpressions.Regex.Split(txtUsername.Text.Trim(), @"[. ]+");
+ string username = cbxUsername.Text;
+
+ if (cbxUsername.SelectedIndex > 0 && cbxUsername.SelectedItem is SavedLogin)
+ {
+ username = ((SavedLogin)cbxUsername.SelectedItem).Username;
+ }
+
+ string[] parts = System.Text.RegularExpressions.Regex.Split(username.Trim(), @"[. ]+");
+
if (parts.Length == 2)
{
netcom.LoginOptions.FirstName = parts[0];
}
else
{
- netcom.LoginOptions.FirstName = txtUsername.Text.Trim();
+ netcom.LoginOptions.FirstName = username.Trim();
netcom.LoginOptions.LastName = "Resident";
}
}
netcom.Login();
+ SaveConfig();
}
private void btnLogin_Click(object sender, EventArgs e)
{
- SaveConfig();
switch (btnLogin.Text)
{
case "Login": BeginLogin(); break;
}
}
- private void txtPassword_TextChanged(object sender, EventArgs e)
- {
- netcom.LoginOptions.IsPasswordMD5 = false;
- }
-
private void cbTOS_CheckedChanged(object sender, EventArgs e)
{
btnLogin.Enabled = cbTOS.Checked;
}
}
+ private void cbxUsername_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ cbxUsername.SelectedIndexChanged -= cbxUsername_SelectedIndexChanged;
+
+ if (cbxUsername.SelectedIndex > 0
+ && cbxUsername.SelectedItem is SavedLogin)
+ {
+ SavedLogin sl = (SavedLogin)cbxUsername.SelectedItem;
+ cbxUsername.Text = sl.Username;
+ cbxUsername.Items[0] = sl.Username;
+ cbxUsername.SelectedIndex = 0;
+ txtPassword.Text = sl.Password;
+ if (sl.GridID == "custom_login_uri")
+ {
+ cbxGrid.SelectedIndex = cbxGrid.Items.Count - 1;
+ txtCustomLoginUri.Text = sl.CustomURI;
+ }
+ else
+ {
+ foreach (var item in cbxGrid.Items)
+ {
+ if (item is Grid && ((Grid)item).ID == sl.GridID)
+ {
+ cbxGrid.SelectedItem = item;
+ break;
+ }
+ }
+ }
+ }
+
+ cbxUsername.SelectedIndexChanged += cbxUsername_SelectedIndexChanged;
+ }
+ }
+
+ public class SavedLogin
+ {
+ public string Username;
+ public string Password;
+ public string GridID;
+ public string CustomURI;
+
+ public OSDMap ToOSD()
+ {
+ OSDMap ret = new OSDMap(4);
+ ret["username"] = Username;
+ ret["password"] = Password;
+ ret["grid"] = GridID;
+ ret["custom_url"] = CustomURI;
+ return ret;
+ }
+
+ public static SavedLogin FromOSD(OSD data)
+ {
+ if (!(data is OSDMap)) return null;
+ OSDMap map = (OSDMap)data;
+ SavedLogin ret = new SavedLogin();
+ ret.Username = map["username"];
+ ret.Password = map["password"];
+ ret.GridID = map["grid"];
+ ret.CustomURI = map["custom_url"];
+ return ret;
+ }
+
+ public override string ToString()
+ {
+ RadegastInstance instance = RadegastInstance.GlobalInstance;
+ string gridName;
+ if (GridID == "custom_login_uri")
+ {
+ gridName = "Custom Login URI";
+ }
+ else if (instance.GridManger.KeyExists(GridID))
+ {
+ gridName = instance.GridManger[GridID].Name;
+ }
+ else
+ {
+ gridName = GridID;
+ }
+ return string.Format("{0} -- {1}", Username, gridName);
+ }
}
}
private string firstName;
private string lastName;
private string password;
- private bool isPasswordMD5 = false;
private string version = string.Empty;
private string channel = string.Empty;
}
+ public static bool IsPasswordMD5(string pass)
+ {
+ return pass.Length == 35 && pass.StartsWith("$1$");
+ }
+
public string FirstName
{
get { return firstName; }
set { password = value; }
}
- public bool IsPasswordMD5
- {
- get { return isPasswordMD5; }
- set { isPasswordMD5 = value; }
- }
-
public StartLocationType StartLocation
{
get { return startLocation; }
string password;
- if (loginOptions.IsPasswordMD5)
+ if (LoginOptions.IsPasswordMD5(loginOptions.Password))
{
password = loginOptions.Password;
}