267 lines
9.1 KiB
C#
267 lines
9.1 KiB
C#
/***********************************************************************
|
|
* File: passwordDialog.cs
|
|
* Author: Juan Carlos Luciani (jluciani@novell.com)
|
|
*
|
|
* Namespace: Novell.Security.ClientPasswordManager
|
|
*
|
|
* Classes implemented: PasswordDialog.
|
|
*
|
|
* Copyright (C) 2004 Novell, Inc.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public
|
|
* License along with this library; if not, write to the Free
|
|
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
***********************************************************************/
|
|
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Collections;
|
|
using System.ComponentModel;
|
|
using System.Windows.Forms;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Novell.Security.ClientPasswordManager
|
|
{
|
|
/// <summary>
|
|
/// Provides a dialog for the acquisition of passwords.
|
|
/// </summary>
|
|
public class passwordDialog : System.Windows.Forms.Form
|
|
{
|
|
private System.Windows.Forms.Label label1;
|
|
private System.Windows.Forms.TextBox passwordField;
|
|
private System.Windows.Forms.Button okBtn;
|
|
private System.Windows.Forms.Button cancelBtn;
|
|
|
|
/// <summary>
|
|
/// Required designer variable.
|
|
/// </summary>
|
|
private System.ComponentModel.Container components = null;
|
|
|
|
/// <summary>
|
|
/// Constructor.
|
|
/// </summary>
|
|
/// <param name="title">Title to used with dialog.</param>
|
|
public passwordDialog(string title)
|
|
{
|
|
// Required for Windows Form Designer support
|
|
InitializeComponent();
|
|
|
|
// Update the form title
|
|
Text = title;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clean up any resources being used.
|
|
/// </summary>
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
if (components != null)
|
|
{
|
|
components.Dispose();
|
|
}
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
#region Windows Form Designer generated code
|
|
/// <summary>
|
|
/// Required method for Designer support - do not modify
|
|
/// the contents of this method with the code editor.
|
|
/// </summary>
|
|
private void InitializeComponent()
|
|
{
|
|
this.label1 = new System.Windows.Forms.Label();
|
|
this.passwordField = new System.Windows.Forms.TextBox();
|
|
this.okBtn = new System.Windows.Forms.Button();
|
|
this.cancelBtn = new System.Windows.Forms.Button();
|
|
this.SuspendLayout();
|
|
//
|
|
// label1
|
|
//
|
|
this.label1.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
|
this.label1.Location = new System.Drawing.Point(16, 24);
|
|
this.label1.Name = "label1";
|
|
this.label1.Size = new System.Drawing.Size(56, 16);
|
|
this.label1.TabIndex = 0;
|
|
this.label1.Text = "Password:";
|
|
//
|
|
// passwordField
|
|
//
|
|
this.passwordField.AcceptsReturn = true;
|
|
this.passwordField.Location = new System.Drawing.Point(96, 24);
|
|
this.passwordField.MaxLength = 64;
|
|
this.passwordField.Name = "passwordField";
|
|
this.passwordField.PasswordChar = '*';
|
|
this.passwordField.Size = new System.Drawing.Size(224, 20);
|
|
this.passwordField.TabIndex = 5;
|
|
this.passwordField.Text = "";
|
|
//
|
|
// okBtn
|
|
//
|
|
this.okBtn.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
|
this.okBtn.Location = new System.Drawing.Point(152, 64);
|
|
this.okBtn.Name = "okBtn";
|
|
this.okBtn.TabIndex = 7;
|
|
this.okBtn.Text = "Ok";
|
|
this.okBtn.Click += new System.EventHandler(this.okBtn_Click);
|
|
//
|
|
// cancelBtn
|
|
//
|
|
this.cancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
|
this.cancelBtn.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
|
this.cancelBtn.Location = new System.Drawing.Point(240, 64);
|
|
this.cancelBtn.Name = "cancelBtn";
|
|
this.cancelBtn.TabIndex = 8;
|
|
this.cancelBtn.Text = "Cancel";
|
|
//
|
|
// passwordDialog
|
|
//
|
|
this.AcceptButton = this.okBtn;
|
|
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
|
|
this.CancelButton = this.cancelBtn;
|
|
this.ClientSize = new System.Drawing.Size(338, 96);
|
|
this.Controls.Add(this.cancelBtn);
|
|
this.Controls.Add(this.okBtn);
|
|
this.Controls.Add(this.passwordField);
|
|
this.Controls.Add(this.label1);
|
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
|
this.MaximizeBox = false;
|
|
this.MinimizeBox = false;
|
|
this.Name = "passwordDialog";
|
|
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
|
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
|
this.Load += new System.EventHandler(this.passwordDialog_Load);
|
|
this.Activated += new System.EventHandler(this.passwordDialog_Activated);
|
|
this.ResumeLayout(false);
|
|
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Handler for form activation event.
|
|
/// </summary>
|
|
private void passwordDialog_Activated(object sender, System.EventArgs e)
|
|
{
|
|
passwordField.Focus();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handler for Ok button click event.
|
|
/// </summary>
|
|
private void okBtn_Click(object sender, System.EventArgs e)
|
|
{
|
|
// Dispose of the dialog and set DialogResult to OK
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
}
|
|
|
|
private void passwordDialog_Load(object sender, System.EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the password entered by the user.
|
|
/// </summary>
|
|
public System.String password { get {return passwordField.Text;}}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Class wrapper around the passwordDialog class. This wrapper is utilized
|
|
/// to hide the use of Gtk# from its users.
|
|
/// </summary>
|
|
public class PasswordDialog
|
|
{
|
|
#region Class Members and Defines
|
|
|
|
// The following strings need to be localized
|
|
private static string m_titleStartText = "Login to ";
|
|
private static string m_titleRealmText = ", Realm: ";
|
|
|
|
// Title that will be used with the dialog
|
|
private string m_dialogTitle;
|
|
|
|
// Input gathered from the user
|
|
private string m_password;
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Constructor.
|
|
/// </summary>
|
|
/// <param name="svcName">Name of service on whose behalf we are acquiring password.</param>
|
|
public PasswordDialog(string svcName)
|
|
{
|
|
// Setup the title that will be used with the dialog
|
|
m_dialogTitle = m_titleStartText + svcName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructor.
|
|
/// </summary>
|
|
/// <param name="svcName">Name of service on whose behalf we are acquiring password.</param>
|
|
/// <param name="realm">Name of realm to which the service belongs, can be empty string or null.</param>
|
|
public PasswordDialog(string svcName, string realm)
|
|
{
|
|
// Setup the appropriate title that will be used with the dialog
|
|
if (realm != null && realm.Length != 0)
|
|
{
|
|
m_dialogTitle = m_titleStartText + svcName + m_titleRealmText + realm;
|
|
}
|
|
else
|
|
{
|
|
m_dialogTitle = m_titleStartText + svcName;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Shows the dialog and gathers the user input.
|
|
/// </summary>
|
|
/// <param name="o">Window owner.</param>
|
|
/// <returns>True if the user input was gathered, else false.</returns>
|
|
public bool Invoke(System.Object o)
|
|
{
|
|
bool retVal;
|
|
|
|
// Instantiate and show passwordDialog
|
|
passwordDialog dialog = new passwordDialog(m_dialogTitle);
|
|
if (dialog.ShowDialog((IWin32Window) o) == DialogResult.OK)
|
|
{
|
|
// Save the password entered
|
|
m_password = dialog.password;
|
|
|
|
// Indicate success
|
|
retVal = true;
|
|
}
|
|
else
|
|
{
|
|
// The user either hit the cancel button or closed
|
|
// the window.
|
|
retVal = false;
|
|
}
|
|
|
|
// Dispose of the dialog
|
|
dialog.Dispose();
|
|
|
|
return retVal;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the password entered by the user.
|
|
/// </summary>
|
|
public System.String password { get {return m_password;}}
|
|
}
|
|
}
|