コード例 #1
0
        public bool Decode(string barCode, string token, out long uid)
        {
            long cat = Convert.ToInt64(barCode.Substring(prefix.Length));

            uid = cat / n;
            long            pwd = cat % n;
            DynamicPassword otp = new DynamicPassword(token, duration);

            return(otp.Verify(pwd.ToString()));
        }
コード例 #2
0
        public string Encode(long uid, string token)
        {
            DynamicPassword otp = new DynamicPassword(token, duration);
            string          pwd = otp.GetPassword(n.ToString().Length - 1);
            long            l   = Convert.ToInt64(pwd);

            long res = uid * n + l;

            return(prefix + res.ToString().PadLeft(16, '0'));
        }