Esempio n. 1
0
        public void Load(string key, string host)
        {
            var foo  = KCore.Security.Hash.MD5(key, R.Security.MasterKey);
            var file = new FileInfo($"{Folder}/{foo}.credential");

            if (!file.Exists)
            {
                throw new KCoreException(LOG, C.MessageEx.InvalidCredential11_0, file);
            }

            this.key   = key;
            LastUpdate = file.LastAccessTime;

            if (LastUpdate.AddMinutes(Expire) < DateTime.Now)
            {
                throw new KCoreException(LOG, C.MessageEx.LoginExpired6_0);
            }

            string text = System.IO.File.ReadAllText(file.ToString());
            var    json = KCore.Security.Hash.Decrypt(text, UserKey);
            var    cred = Newtonsoft.Json.JsonConvert.DeserializeObject <PersonalSerialize>(json);

#if !DEBUG
            if (cred.host != host)
            {
                throw new KCoreException(LOG, C.MessageEx.E_InvalidKey9);
            }
#endif
            this.User        = cred.user;
            this.Instance    = cred.instance;
            this.Host        = cred.host;
            this.key         = cred.key;
            this.UId         = cred.uid;
            this.CryptPasswd = cred.cryppasswd;
            this.Created     = cred.created;
            this.Properties  = cred.properties;
        }