Exemple #1
0
 public bool Login(string username, string password)
 {
     if (Authorizer.CheckAuthorization(username, password))
     {
         this.username     = username;
         this.isAuthorized = true;
         return(true);
     }
     return(false);
 }
Exemple #2
0
        public static bool AddNewAuthorization(string username, string password)
        {
            if (!Authorizer.CheckAuthorization(username, password))
            {
                if (File.Exists(filesFolderPath + @"/Authentifications.json"))
                {
                    string fileContent = File.ReadAllText(filesFolderPath + @"/Authentifications.json");

                    JObject json = null;
                    JArray  authentifications = null;

                    if (!String.IsNullOrEmpty(fileContent))
                    {
                        json = JObject.Parse(fileContent);
                        authentifications = json.GetValue("authentifications").ToObject <JArray>();
                        json.Remove("authentifications");
                    }
                    else
                    {
                        authentifications = new JArray();
                        json = new JObject();
                    }

                    JObject authentification = new JObject();
                    authentification.Add("username", username);
                    authentification.Add("password", password);

                    authentifications.Add(authentification);
                    json.Add("authentifications", authentifications);

                    File.WriteAllText(filesFolderPath + @"/Authentifications.json", json.ToString());

                    return(true);
                }
            }
            return(false);
        }