void issue_15_it_should_return_emtpy_array_when_decoding_characters_missing_in_alphabet()
        {
            var hashids = new Hashids(salt: "Salty stuff", alphabet: "qwerty1234!¤%&/()=", seps: "1234");
            var numbers = hashids.Decode("abcd");

            numbers.Length.Should().Be(0);

            var hashids2 = new Hashids();

            hashids.Decode("13-37").Length.Should().Be(0);
            hashids.DecodeLong("32323kldffd!").Length.Should().Be(0);

            var hashids3 = new Hashids(alphabet: "1234567890;:_!#¤%&/()=", seps: "!#¤%&/()=");

            hashids.Decode("asdfb").Length.Should().Be(0);
            hashids.DecodeLong("asdfgfdgdfgkj").Length.Should().Be(0);
        }
        public bool TryDecodeLong(string input, out long output)
        {
            var results    = _hashIds.DecodeLong(input);
            var hasResults = results.Any();

            output = hasResults ? results.Single() : default;

            return(hasResults);
        }
        private void Issue23_It_should_Encode_hash()
        {
            var hashId  = new Hashids(salt: "0Q6wKupsoahWD5le", alphabet: "abcdefghijklmnopqrstuvwxyz1234567890!", seps: "cfhistu");
            var source  = new long[] { 35887507618889472L, 30720L, Int64.MaxValue };
            var encoded = hashId.EncodeLong(source);

            var result = hashId.DecodeLong(encoded);

            result.ShouldBe(source);
        }
Esempio n. 4
0
 public long?HashDecodeLongId(string hashValue)
 {
     try
     {
         return(hashids.DecodeLong(hashValue).First());
     }
     catch (Exception)
     {
         return(null);
     }
 }
        public static string Decode(string salt, string code)
        {
            var hashids = new Hashids(salt, 4, Alphabet);
            var decode  = hashids.DecodeLong(code);

            if (decode.Length > 0)
            {
                return(decode[0].ToString());
            }
            return(null);
        }
Esempio n. 6
0
            public void EncodedValueShouldReturnSameValueWhenDecoded()
            {
                string Alphabet  = "acefghjkmnrstwxyz23456789";
                var    salt      = "BatteryHorseStapleCorrect";
                var    sessionId = SessionIdHelper.GenerateSessionId(salt, DateTime.UtcNow);
                var    hashids   = new Hashids(salt, 4, Alphabet);
                var    digits    = hashids.DecodeLong(sessionId).First();

                var decode = SessionIdHelper.Decode(salt, sessionId);

                decode.Should().Be(digits.ToString());
            }
Esempio n. 7
0
        void it_decodes_an_encoded_long()
        {
            hashids.DecodeLong("NV").Should().Equal(new[] { 1L });
            hashids.DecodeLong("21OjjRK").Should().Equal(new[] { 2147483648L });
            hashids.DecodeLong("D54yen6").Should().Equal(new[] { 4294967296L });

            hashids.DecodeLong("KVO9yy1oO5j").Should().Equal(new[] { 666555444333222L });
            hashids.DecodeLong("4bNP1L26r").Should().Equal(new[] { 12345678901112L });
            hashids.DecodeLong("jvNx4BjM5KYjv").Should().Equal(new[] { Int64.MaxValue });
        }
Esempio n. 8
0
        public static long Decode(object key)
        {
            var hashids = new Hashids("meu salt", 5);

            var decoded = hashids.DecodeLong(key as string);

            if (decoded == null || decoded.Length == 0)
            {
                return(0);
            }

            return(decoded[0]);
        }
        public long DecryptLong(string cipherText)
        {
            if (string.IsNullOrEmpty(cipherText) || string.IsNullOrWhiteSpace(cipherText))
            {
                return(0);
            }

            var result = _hashId.DecodeLong(_useGuidFormat ? GuidFormat(cipherText, HashIdOperation.Decrypt) : cipherText);

            if (result.Length == 1)
            {
                return(result[0]);
            }
            throw new DecryptHashIdException();
        }
Esempio n. 10
0
        void issue_12_should_not_throw_out_of_range_exception()
        {
            var hash = new Hashids("zXZVFf2N38uV");
            var longs = new List<long>();
            var rand = new Random();
            var valueBuffer = new byte[8];
            var randLong = 0L;
            for (var i = 0; i < 100000; i++)
            {
                rand.NextBytes(valueBuffer);
                randLong = BitConverter.ToInt64(valueBuffer, 0);
                longs.Add(Math.Abs(randLong));
            }

            var encoded = hash.EncodeLong(longs);
            var decoded = hash.DecodeLong(encoded);
            decoded.Should().Equal(longs.ToArray());
        }
        private void Issue_12_should_not_throw_out_of_range_exception()
        {
            var hash        = new Hashids("zXZVFf2N38uV");
            var longs       = new List <long>();
            var rand        = new Random();
            var valueBuffer = new byte[8];

            for (var i = 0; i < 100000; i++)
            {
                rand.NextBytes(valueBuffer);
                var randLong = BitConverter.ToInt64(valueBuffer, 0);
                longs.Add(Math.Abs(randLong));
            }

            var encoded = hash.EncodeLong(longs);
            var decoded = hash.DecodeLong(encoded);

            decoded.ShouldBe(longs.ToArray());
        }
Esempio n. 12
0
        public async Task <ActionResult> GeneratedEmail([FromServices] QRContext context, string id)
        {
            var strSalt = Environment.GetEnvironmentVariable("deploy");

            var  hashids = new Hashids(strSalt);
            long idUser  = hashids.DecodeLong(id)[0];
            var  user    = context.SimpleUser.FirstOrDefault(it => it.Iduser == idUser);

            if (user == null)
            {
                return(Content("user does not exists"));
            }
            user.ConfirmedByEmail = true;
            await context.SaveChangesAsync();

            await SignUser(user);

            return(RedirectToAction("index"));
        }
Esempio n. 13
0
 public long Decode(string s)
 {
     return(h.DecodeLong(s)[0]);
 }
Esempio n. 14
0
 public long DecodeValue(string id)
 {
     return(_hashIds.DecodeLong(id)[0]);
 }
 public static long DecodeAccountLegalEntityId(string hash)
 {
     return(AccountLegalEntityHashGenerator.DecodeLong(hash).First());
 }
 public static long Decode(string hash)
 {
     return(HashGenerator.DecodeLong(hash).First());
 }
 public long DecodeValue(string id)
 {
     ValidateInput(id);
     return(_hashIds.DecodeLong(id)[0]);
 }
Esempio n. 18
0
        public long Decrypt(string hash)
        {
            var hashids = new Hashids(_salt);

            return(hashids.DecodeLong(hash)[0]);
        }