public static SecurityCodePair GenerateSmsCode(TimeSpan expirationPeriod) { Argument.Satisfies(expirationPeriod, x => x.Ticks > 0, "expirationPeriod", "Expiration period should be positive"); using (var rng = new RNGCryptoServiceProvider()) { var byteCode = new byte[8]; rng.GetBytes(byteCode); var code = BitConverter.ToUInt64(byteCode, 0); var smsCode = (code % 100000UL).ToString(CultureInfo.InvariantCulture).PadLeft(6, '0'); var id = Guid.NewGuid(); var privateCode = new SecurityCode(id, expirationPeriod, smsCode); var publicCode = new PublicSecurityCode(id, smsCode); return(new SecurityCodePair(privateCode, publicCode)); } }
private SecurityCodePair(SecurityCode privateSecurityCode, PublicSecurityCode publicSecurityCode) { _privateSecurityCode = privateSecurityCode; _publicSecurityCode = publicSecurityCode; }