示例#1
0
        protected void btnGeneratePassword_Click(object sender, EventArgs e)
        {
            var generator = new  GeneradorPassword(minimumLengthPassword: 8,
                                                   maximumLengthPassword: 15,
                                                   minimumUpperCaseChars: 1,
                                                   minimumNumericChars: 1,
                                                   minimumSpecialChars: 1);
            string password     = generator.Generate();
            var    pass         = Utils.EncryptStringToBytes_Aes(password);
            var    user         = UserName.Text.Trim().ToUpperInvariant();
            var    validaUpdate = _idalttcol300.updateUFIN(ref user, ref pass, ref strError);

            if (validaUpdate)
            {
                string siteName         = ConfigurationManager.AppSettings["enlaceRet"].ToString();
                string rutaServUserName = string.Empty;
                string rutaServPassword = string.Empty;
                rutaServUserName      = UrlBaseBarcode + "/Barcode/BarcodeHandler.ashx?data=" + UserName.Text.Trim().ToUpperInvariant() + "&code=Code128&dpi=96";
                imgUniqueUserName.Src = !string.IsNullOrEmpty(UserName.Text.Trim().ToUpperInvariant()) ? rutaServUserName : "";
                imgUniqueUserName.Style.Add("width", "2in");
                imgUniqueUserName.Style.Add("height", ".6in");
                rutaServPassword      = UrlBaseBarcode + "/Barcode/BarcodeHandler.ashx?data=" + password + "&code=Code128&dpi=96&printDataText=false";
                imgUniquePassword.Src = !string.IsNullOrEmpty(password) ? rutaServPassword : "";
                imgUniquePassword.Style.Add("width", "2in");
                imgUniquePassword.Style.Add("height", ".6in");
                Page.ClientScript.RegisterStartupScript(GetType(), "none", "<script>setTimeout(function(){printContent('Contenido_UpdatePanel1')},3000);</script>", false);
                btnGeneratePassword.Enabled = false;
                return;
            }
        }
 /// <summary>
 /// Constructor. La contraseña tendrá 8 caracteres, incluyendo una letra mayúscula, 
 /// un número y un símbolo
 /// </summary>
 public static string GetPassword()
 {
     // Se crea un método estático para facilitar el uso
     GeneradorPassword gp = new GeneradorPassword();
     return gp.GetNewPassword();
 }