تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
ممكن مساعدة في حل مشكل البرنامج
#1
السلام عليكم
ممكن مساعدة عندي برنامج ملرتبط بــ Firebase قاعدة بيانات
و البرنامج بكلمة سر ثابتة لكل الأعضاء
أريد تغييرها كل 24 ساعة 
و لكل عضو كود خاض به 
شكرا لكم



كود :
 protected string current_key, saved_key, enterd_key;
       public string AuthSecret = "";
       public string BasePath = "  /";
       public string KeyName = "key";

       public KeysController(string key = null){
           this.current_key = this.SyncKey();
           this.saved_key = this.GetSavedKey();
           this.enterd_key = key;
           this.CanAccess();

           if (this.current_key != null)
               this.VerifyKey();
       }

       public bool CanAccess()
       {
           if (current_key == '"'+ enterd_key +'"' || current_key == '"' + saved_key + '"')
               return true;
           else
               return false;
       }

       public bool VerifyKey(){
           if ('"' + enterd_key +'"' != current_key) return false;

           SaveKey();
           return true;
       }

       private void SaveKey()
       {
           Key key = new Key(enterd_key);

           try
           {
               // serialize JSON to a string and then write string to a file
               File.WriteAllText(@"c:\registerd_key.json", JsonConvert.SerializeObject(key));

           }
           catch (System.UnauthorizedAccessException)
           {
               MessageBox.Show("برجاء تشغيل البرنامج كمسؤل");
               return;
           }

           // serialize JSON directly to a file
           using (StreamWriter file = File.CreateText(@"c:\registerd_key.json"))
           {
               JsonSerializer serializer = new JsonSerializer();
               serializer.Serialize(file, key);
           }

       }

       private string GetSavedKey()
       {
           try
           {
               // deserialize JSON directly from a file
               using (StreamReader file = File.OpenText(@"c:\registerd_key.json"))
               {
                   JsonSerializer serializer = new JsonSerializer();
                   Key key2 = (Key)serializer.Deserialize(file, typeof(Key));

                   return key2.key ?? null;
               }
           }
           catch
           {
               return null;
           }
       }

       private string SyncKey()
       {
           IFirebaseConfig config = new FirebaseConfig
           {
               AuthSecret = AuthSecret,
               BasePath = BasePath,
           };

           IFirebaseClient client = new FirebaseClient(config);

           return client.Get(KeyName).Body.ToString();
       }
الرد }}}
تم الشكر بواسطة:



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم