using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CMS.FormControls;
using CMS.GlobalHelper;
using CMS.SettingsProvider;
public partial class CMSFormControls_System_Password : FormEngineUserControl
{
#region "Variables"
///
/// Default hidden password value.
///
private string hiddenPassword = "********";
///
/// Current password.
///
private string mPassword = String.Empty;
///
/// Indicates whether textbox should be filled.
///
private bool fillPassword = false;
///
/// Indicates whether load phase finished.
///
private bool loadFinished = false;
#endregion
#region "Properties"
///
/// Gets or sets the value.
///
public override object Value
{
get
{
return Password;
}
set
{
Password = Convert.ToString(value);
}
}
///
/// Gets or sets the enabled.
///
public override bool Enabled
{
get
{
return txtPassword.Enabled;
}
set
{
txtPassword.Enabled = value;
}
}
///
/// Gets or sets the current password.
///
public string Password
{
get
{
// Get password from textbox if is set
if (loadFinished && RequestHelper.IsPostBack() && (CMSString.Compare(txtPassword.Text, hiddenPassword, StringComparison.CurrentCulture) != 0))
{
Password = txtPassword.Text;
}
else
{
mPassword = GetPassword();
}
return mPassword;
}
set
{
mPassword = value;
SetPassword(mPassword);
}
}
///
/// Returns ClientID of the textbox with password.
///
public override string ValueElementID
{
get
{
return txtPassword.ClientID;
}
}
#endregion
#region "Methods"
///
/// OnLoad - Set loading flag.
///
protected void Page_Load(object sender, EventArgs e)
{
CheckMinMaxLength = true;
CheckRegularExpression = true;
loadFinished = true;
}
///
/// Encrypt and save password. Encryption method is not implemented yet!
///
/// Password value
protected void SetPassword(string password)
{
fillPassword = false;
if (!String.IsNullOrEmpty(password))
{
fillPassword = true;
}
mPassword = password;
}
///
/// Decrypt and returns password. Decryption method is not implemented yet!
///
protected string GetPassword()
{
return ValidationHelper.GetString(mPassword, String.Empty);
}
///
/// OnPreRender override - set password text.
///
/// EventArgs
protected override void OnPreRender(EventArgs e)
{
if (fillPassword)
{
txtPassword.Attributes.Add("value", hiddenPassword);
}
else
{
txtPassword.Attributes.Remove("value");
}
base.OnPreRender(e);
}
#endregion
}