private static IPrivacyProvider GetPrivacyProvider(string password, PasswordType passwordType, string encryption, EncryptionType encryptionType) { IPrivacyProvider provider; IAuthenticationProvider auth; if (passwordType == PasswordType.SHA) { auth = new SHA1AuthenticationProvider(new OctetString(password)); } else { auth = new MD5AuthenticationProvider(new OctetString(password)); } if (encryptionType == EncryptionType.DES) { provider = new Security.DESPrivacyProvider(new OctetString(encryption), auth); } else { provider = new Security.AESPrivacyProvider(new OctetString(encryption), auth); } return(provider); }
/// <summary> /// Username security token constructor /// </summary> /// <param name="username">User name</param> /// <param name="password">Password</param> /// <param name="passwordType">Password type: PasswordText, PasswordDigest</param> public UsernameSecurityToken(string username, string password, PasswordType passwordType = PasswordType.PasswordText) { _username = username; _created = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); // https://www.w3.org/TR/xmlschema-2/#dateTime _nonce = CalculateNonce(); _password = CreatePassword(password, _nonce, _created, passwordType); }
public bool ValidateNewPasswordEncryptedWithOldLm(PasswordType passwordType, _SAMPR_ENCRYPTED_USER_PASSWORD target) { _SAMPR_ENCRYPTED_USER_PASSWORD expected = GetNewPasswordEncryptedWithOldLm(passwordType); bool isSame = ObjectUtility.DeepCompare(expected, target); return(isSame); }
// optional, coming: login, URl, comment /// <summary> /// Constructor /// </summary> /// <param name="name">initial site name</param> /// <param name="counter">initial counter value</param> public SiteEntry(string name, int counter) { SiteName = name; Login = string.Empty; Counter = counter; Type = PasswordType.LongPassword; }
/// <summary> /// Load from a stream (typically: an XML file) /// </summary> /// <param name="s">open stream</param> public void Load(Stream s) { XDocument doc = XDocument.Load(s); UserName = doc.Root.Element("UserName").Value; Sites.Clear(); foreach (var node in doc.Root.Element("Sites").Elements("Site")) { PasswordType pwType = PasswordType.LongPassword; // standard var typeElement = node.Element("Type"); if (null != typeElement) { pwType = SerializePasswordTypeType.First(row => row.Value == typeElement.Value).Key; } SiteEntry entry = new SiteEntry( siteName: node.Element("SiteName").Value, counter: int.Parse(node.Element("Counter").Value), login: node.Element("Login").Value, type: pwType ); Sites.Add(entry); } }
/// <summary> /// Constructor setting all properties /// </summary> /// <param name="siteName">initial site name</param> /// <param name="counter">initial counter value</param> /// <param name="login">initial login value</param> /// <param name="type">initial type</param> public SiteEntry(string siteName, int counter, string login, PasswordType type) { SiteName = siteName; Login = login; Counter = counter; Type = type; }
/// <summary> /// Copy constructor /// </summary> public SiteEntry(SiteEntry copyFrom) { SiteName = copyFrom.SiteName; Login = copyFrom.Login; Counter = copyFrom.Counter; Type = copyFrom.Type; }
public SiteEntry(string siteName, int counter, string login, PasswordType type) { this.SiteName = siteName; this.Login = login; this.Counter = counter; this.Type = type; }
partial void RecalcPassword(MonoMac.Foundation.NSObject sender) { // get data from UI string userName = UserName.StringValue; string masterPass = MasterKey.StringValue; if (SitesTable.SelectedRow < 0) { return; } var currentSite = Config.Sites[SitesTable.SelectedRow]; string siteName = currentSite.SiteName; int counter = currentSite.Counter; PasswordType pwType = currentSite.Type; SaveSettings(); // calculate result var masterkey = Algorithm.CalcMasterKey(userName, masterPass); var siteKey = Algorithm.CalcTemplateSeed(masterkey, siteName, counter); string result = Algorithm.CalcPassword(siteKey, pwType); // display result GeneratedPassword.StringValue = result; }
/// <summary> /// Validates the optical passwords /// </summary> // Revision History // MM/DD/YY Who Version ID Number Description // -------- --- ------- -- ------ ------------------------------------------- // 09/17/09 RCG 2.30.00 Created // 09/19/14 jrf 4.00.63 WR 534158 Modified way test details are set. private void ValidateOpticalPasswords() { string Details = ""; string Reason = ""; bool Skipped = File.Exists(m_strProgramFile) == false || EDLFile.IsEDLFile(m_strProgramFile) == false; ProcedureResultCodes ValidationResult = ProcedureResultCodes.COMPLETED; if (IsAborted == false) { foreach (CENTRON_AMI.OpticalPasswords PasswordType in Enum.GetValues(typeof(CENTRON_AMI.OpticalPasswords))) { if (Skipped == false) { ValidationResult = m_AmiDevice.ValidateOpticalPasswords(m_strProgramFile, PasswordType); Details = GetSecurityValidationDetails(ValidationResult); if (ProcedureResultCodes.INVALID_PARAM == ValidationResult) { Details += ", " + TestResources.PasswordNotConsistentWithProgram; } } else { Reason = TestResources.ReasonProgramFileNeededToValidate; Details = TestResources.NoProgram; } AddTestDetail(PasswordType.ToDescription(), GetResultString(Skipped, ProcedureResultCodes.COMPLETED == ValidationResult), Details, Reason); } } }
/// <summary> /// main algorithm: generate the site specific password /// </summary> private static string GeneratePassword(string userName, string siteName, PasswordType type, int counter, string masterPassword, bool toClipboard = false) { var masterkey = Algorithm.CalcMasterKey(userName, masterPassword); var templateSeed = Algorithm.CalcTemplateSeed(masterkey, siteName, counter); return(Algorithm.CalcPassword(templateSeed, type)); }
/// <summary> /// パスワードの生成 /// </summary> /// <param name="length"></param> /// <param name="types"></param> /// <returns></returns> public static string Create(int length, PasswordType[] types) { var useTypes = new PasswordType[length]; var useTypesLength = types.Length; for (var i = 0; i < useTypesLength; i++) { useTypes[i] = types[i]; } for (var i = useTypesLength; i < length; i++) { useTypes[i] = types[random.Next(0, types.Length)]; } List <char> chars = new List <char>(); foreach (PasswordType useType in useTypes) { chars.Add(getAllowedChar(useType)); } string password = new String(chars.ToArray()); return(password); }
/// <summary> /// 字符串加密 /// </summary> /// <param name="PasswordString">要加密的字符串</param> /// <param name="PasswordFormat">要加密的类别</param> /// <returns></returns> static public string EncryptPassword(string PasswordString, PasswordType PasswordFormat) { #region switch (PasswordFormat) { case PasswordType.SHA1: { passWord = FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordString, "SHA1"); break; } case PasswordType.MD5: { passWord = FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordString, "MD5").Substring(8, 16).ToLower(); break; } default: { passWord = string.Empty; break; } } return(passWord); #endregion }
/// <summary> /// main algorithm: generate the site specific password /// </summary> private static void GeneratePassword(string userName, string siteName, PasswordType type, int counter, string masterPassword) { var masterkey = Algorithm.CalcMasterKey(userName, masterPassword); var templateSeed = Algorithm.CalcTemplateSeed(masterkey, siteName, counter); var generatedPassword = Algorithm.CalcPassword(templateSeed, type); Console.WriteLine(generatedPassword); }
private string HashPassword(string password, PasswordType type) { if (type == PasswordType.LegacyMd5) { password = HashPasswordLegacyMd5(password); } return(Crypto.HashPassword(password)); }
public static string Generate(short length, PasswordType require) { bool requireUpper = (require & PasswordType.Upper) > 0; bool requireLower = (require & PasswordType.Lower) > 0; bool requireNumeric = (require & PasswordType.Numeric) > 0; bool requireSpecial = (require & PasswordType.Special) > 0; return(Generate(length, requireUpper, requireLower, requireNumeric, requireSpecial)); }
private void AddPasswordType(PasswordType passwordType) { var item = new DataGridViewRow(); item.CreateCells(dgvItems, passwordType.Name, passwordType.Fields.Count); item.Tag = passwordType; dgvItems.Rows.Add(item); item.Selected = true; }
public JsonResult ModifyPwd(string oldPassword, string newPassword, PasswordType passwordType) { var tokenInfo = JwtUtil.GetTokenInfo(); return(new JsonResult() { Data = settingService.ModifyPassword(tokenInfo.Number, oldPassword, newPassword, passwordType) }); }
private bool VerifyHashedPassword(string hashedPassword, string password, PasswordType type) { if (type == PasswordType.LegacyMd5) { password = HashPasswordLegacyMd5(password); } return(Crypto.VerifyHashedPassword(hashedPassword, password)); }
/// <summary> /// 字符串加密 /// </summary> /// <param name="s"></param> /// <param name="passwordType">字符串加密类型</param> /// <returns></returns> public static string Encryption(this string s, PasswordType passwordType) { if (passwordType == PasswordType.BASE64) { return(Convert.ToBase64String(System.Text.ASCIIEncoding.Default.GetBytes(s))); } return(string.Empty); }
/// <summary> /// main algorithm: generate the site specific password /// </summary> private static void GeneratePassword(string userName, string siteName, PasswordType type, int counter, string masterPassword) { var masterkey = Algorithm.CalcMasterKey(userName, masterPassword); var templateSeed = Algorithm.CalcTemplateSeed(masterkey, siteName, counter); var generatedPassword = Algorithm.CalcPassword(templateSeed, type); System.IO.File.WriteAllText(Directory.GetCurrentDirectory() + "\\WriteText.txt", generatedPassword); Console.WriteLine(generatedPassword); }
public void TryGetAllValues_Enum(PasswordType type, bool expSuccess, string vals, string expError) { byte[] expValues = vals is null?Array.Empty <byte>() : Encoding.UTF8.GetBytes(vals); PasswordService service = new(); bool success = service.TryGetAllValues(type, out byte[] actualValues, out string actualError); Assert.Equal(expSuccess, success); Assert.Equal(expValues, actualValues); Assert.Equal(expError, actualError); }
public static string Generate(PasswordType type) { var chars = GetAvailableChars(type); var password = string.Empty; for (var i = 0; i < 16; i++) { password += chars[Random.Next(chars.Length)]; } return(password); }
public PasswordTypeTab(PasswordType passwordType, Configuration configuration) { InitializeComponent(); Controls.Add(grid); Configuration = configuration; PasswordType = passwordType; Text = passwordType.Name; }
private static CredentialsType createPasswordCredentials(string clearValue) { PasswordType passwordType = new PasswordType(); passwordType.value = createProtectedStringType(clearValue); CredentialsType retval = new CredentialsType(); retval.password = passwordType; return(retval); }
public static PasswordType Execute(IWin32Window owner, PasswordTypes passwordTypes, PasswordType passwordType) { using (var form = new EditPasswordTypeForm()) { form.Init(passwordTypes, passwordType); if (form.ShowDialog(owner) == DialogResult.OK) return form.SelectedPasswordType; return null; } }
public GetV3Query(string userName, VersionCode versionCode, IPAddress ipAddress, int port, string password, PasswordType passwordType, string encryption, EncryptionType encryptionType, string oidId) { UserName = userName; VersionCode = versionCode; IpAddress = ipAddress; Port = port; Password = password; PasswordType = passwordType; Encryption = encryption; EncryptionType = encryptionType; OID_Id = oidId; }
public SetV3Command(string userName, VersionCode versionCode, IPAddress ipAddress, int port, string password, PasswordType passwordType, string encryption, EncryptionType encryptionType, OID oid) { UserName = userName; VersionCode = versionCode; IpAddress = ipAddress; Port = port; Password = password; PasswordType = passwordType; Encryption = encryption; EncryptionType = encryptionType; OID = oid; }
static char[] GetAvailableChars(PasswordType type) { switch (type) { case PasswordType.Low: return("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYX1234567890".ToCharArray()); case PasswordType.High: return(GetAvailableChars(PasswordType.Low).Concat("!@#$%^&*()_+-=".ToCharArray()).ToArray()); default: throw new NotImplementedException(); } }
public ValidateCodeProvider(int userId, PasswordType codeType) : this() { this._codeType = codeType; try { var fac = UserModuleFactory.GetUserModuleInstance(); var user = fac.GetUserByID(userId); this._userCode = user.UserCode; } catch (Exception ex) { this._userCode = null; } }
/// <summary> /// Calculate the password for the site based on the password type. /// </summary> /// <returns>The site password.</returns> /// <param name="templateSeedForPassword">Template seed for password.</param> /// <param name="typeOfPassword">Type of password.</param> public static string CalcPassword(byte[] templateSeedForPassword, PasswordType typeOfPassword) { string[] templates = TemplateForType[typeOfPassword]; string template = templates[templateSeedForPassword[0] % templates.Length]; char[] password = new char[template.Length]; for (int i = 0; i < password.Length; i++) { string characterGroup = CharacterGroup[template[i]]; // get charactergroup from template password[i] = characterGroup[templateSeedForPassword[i + 1] % characterGroup.Length]; } return(new string(password)); // convert character array to string }
public static char getAllowedChar(PasswordType type) { switch (type.Value) { case PasswordType.AlphabetValue: return(AlphabetRandom()); case PasswordType.NumberValue: return(NumberRandom()); default: throw new ArgumentException(String.Format("{0} is not an even number", type.Value), nameof(type)); } }
public bool ChangePassword(string username, string newPassword, PasswordType passwordType) { try { using (var conn = _connectionProvider.GetConnection()) { conn.Execute("UPDATE tblUsers SET Password = @Password, PasswordType = @PasswordType WHERE Name = @Username", new { Password = newPassword, PasswordType = passwordType, Username = username }); } return(true); } catch (Exception) { } return(false); }
public static bool Execute(IWin32Window owner, PasswordDocument document, Configuration config, out PasswordType result) { using (var form = new SelectTypeForm()) { form.Init(document, config); if (form.ShowDialog(owner) == DialogResult.OK) { result = form.SelectedType; return true; } result = null; return false; } }
public string GeneratePassword(PasswordType type, int length) { if (type == PasswordType.ToCopy || type == PasswordType.ToType) { IEnumerable <char> available; if (type == PasswordType.ToCopy) { available = SmallAlpha.Concat(BigAlpha).Concat(Digits).Concat(Special); } else { //PasswordType.ToType available = SmallAlpha.Concat(BigAlpha).Concat(Digits); } return(GenerateRandomPassword(available.ToArray(), length)); } return(GenerateRememberPassword(length)); }
/// <summary> /// helper: select password type from list based on string /// </summary> private static PasswordType ExtractTypeFromString(PasswordType[] types, string typeAsString) { int index; // try index if (int.TryParse(typeAsString, out index)) { // is a number return types[index]; } // try to find best match foreach (var type in types) { if (type.ToString().ToLowerInvariant().Contains(typeAsString.ToLowerInvariant())) { // match, OK return type; } } // not found throw new ArgumentException("Could not find type, specify as index or a part of the name (case insensitive)."); }
/// <summary> /// 字符串加密 /// </summary> /// <param name="PasswordString">要加密的字符串</param> /// <param name="PasswordFormat">要加密的类别</param> /// <returns></returns> public static string EncryptPassword(string PasswordString, PasswordType PasswordFormat) { #region switch (PasswordFormat) { case PasswordType.SHA1: { passWord = FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordString, "SHA1"); break; } case PasswordType.MD5: { passWord = FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordString, "MD5").Substring(8, 16).ToLower(); break; } default: { passWord = string.Empty; break; } } return passWord; #endregion }
public string GeneratePassword(int length, PasswordType type) { string keys = ""; string words = ""; switch (type) { case PasswordType.Weaken: keys = key1; break; case PasswordType.Weak: keys = key1 + key2; break; case PasswordType.Normal: keys = key1 + key2 + key3; break; case PasswordType.Strong: keys = key1 + key2 + key3 + key4; break; default: throw new NotImplementedException(); } int index; for (int i = 0; i < length; i++) { index = oRandom.Next(keys.Length); words += keys[index]; } return words; }
private void BtnOkClick(object sender, EventArgs e) { if (_passwordType == null) _passwordType = _passwordTypes.Add(); _passwordType.Name = tbName.Text; var fields = GetFields(); _passwordType.Fields.Sync(fields); }
/// <summary> /// main algorithm: generate the site specific password /// </summary> private static void GeneratePassword(string userName, string siteName, PasswordType type, int counter, string masterPassword) { var masterkey = Algorithm.CalcMasterKey(userName, masterPassword); var templateSeed = Algorithm.CalcTemplateSeed(masterkey, siteName, counter); var generatedPassword = Algorithm.CalcPassword(templateSeed, type); Console.WriteLine(generatedPassword); }
private void Init(PasswordTypes passwordTypes, PasswordType passwordType) { _passwordTypes = passwordTypes; _passwordType = passwordType; if (_passwordType == null) Text = "Добавление"; else { Text = "Редактирование"; tbName.Text = _passwordType.Name; Fill(); } RefreshUI(); }
private void AddTypeTab(PasswordType passwordType) { var tab = new PasswordTypeTab(passwordType, Configuration); Tabs.Add(tab); }
public PasswordTypeTab FindTypeTab(PasswordType passwordType) { return Tabs.FirstOrDefault(tab => tab.PasswordType.Equals(passwordType)); }
public SecurityHeader(string systemUser, string systemPassword, PasswordType systemPasswordType = PasswordType.ClearText) { this.SystemUser = systemUser; this.SystemPassword = systemPassword; this.SystermPasswordType = systemPasswordType; }
private static CredentialsType createPasswordCredentials(string clearValue) { PasswordType passwordType = new PasswordType(); passwordType.value = createProtectedStringType(clearValue); CredentialsType retval = new CredentialsType(); retval.password = passwordType; return retval; }
public bool ValidateNewPasswordEncryptedWithOldLm(PasswordType passwordType, _SAMPR_ENCRYPTED_USER_PASSWORD target) { _SAMPR_ENCRYPTED_USER_PASSWORD expected = GetNewPasswordEncryptedWithOldLm(passwordType); bool isSame = ObjectUtility.DeepCompare(expected, target); return isSame; }
using System;
public _SAMPR_ENCRYPTED_USER_PASSWORD GetNewPasswordEncryptedWithOldLm(PasswordType passwordType) { _SAMPR_ENCRYPTED_USER_PASSWORD encryptedPwd = new _SAMPR_ENCRYPTED_USER_PASSWORD(); encryptedPwd.Buffer = new byte[encryptedPwdSize + pwdLenSize]; Encoding targetEncoding; if (passwordType == PasswordType.Oem) { // Windows OEM encoding is ASCII targetEncoding = Encoding.ASCII; } else if (passwordType == PasswordType.Unicode) { targetEncoding = Encoding.Unicode; } else { throw new InvalidOperationException("Invalid password type"); } // Get new password bytes byte[] newPwdBytes = targetEncoding.GetBytes(newPwd); // Copy password bytes to the tail of the encryptedPwdSize bytes of buffer Array.Copy(newPwdBytes, 0, encryptedPwd.Buffer, encryptedPwdSize - newPwdBytes.Length, newPwdBytes.Length); // Set password length for the last pwdLenSize bytes of the (encryptedPwdSize + pwdLenSize) bytes byte[] lengthBytes = BitConverter.GetBytes(newPwdBytes.Length); Array.Copy(lengthBytes, 0, encryptedPwd.Buffer, encryptedPwdSize, lengthBytes.Length); // Get LM hash of existing password byte[] oldLmowf = GetHashWithLMOWFv1(existingPwd); // Do RC4 encryption encryptedPwd.Buffer = RC4Encrypt(encryptedPwd.Buffer, 0, encryptedPwd.Buffer.Length, oldLmowf); return encryptedPwd; }