Ejemplo n.º 1
0
        //Register the system admin
        public Tuple <bool, string> RegisterMaster(string username, string pass)
        {
            Logger.logSensitive(this, System.Reflection.MethodBase.GetCurrentMethod());
            Tuple <bool, string> ans = name_and_pass_check(username, pass);

            if (!ans.Item1)
            {
                return(ans);
            }

            User System_Admin = new User(0, username, false, true);

            users.Add(username, System_Admin);
            string sha1 = SB.CalcSha1(pass);

            Users_And_Hashes.Add(username, sha1);
            DbUser dbadmin = DbManager.Instance.GetUser(username);

            if (dbadmin == null)
            {
                DbManager.Instance.InsertUser(AdapterUser.CreateDBUser(username, false, true, false));
                DbManager.Instance.InsertPassword(AdapterUser.CreateNewPasswordEntry(username, sha1), true);
            }
            return(new Tuple <bool, string>(true, ""));
        }
Ejemplo n.º 2
0
        //Login to Unlogged Register User with valid user name and pass.
        public Tuple <bool, string> Login(string username, string pass, bool isGuest = false)
        {
            Logger.logSensitive(this, System.Reflection.MethodBase.GetCurrentMethod());
            if (isGuest)
            {
                string Uname = addGuest();
                return(new Tuple <bool, string>(true, Uname));
                //No need to Insert Guest to DB
            }
            Tuple <bool, string> ans = check_args(username, pass);

            if (!ans.Item1)
            {
                return(ans);
            }
            string sha1 = SB.CalcSha1(pass);
            string temp_pass_hash;

            if (!Users_And_Hashes.TryGetValue(username, out temp_pass_hash))
            {
                return(new Tuple <bool, string>(false, "No such User: "******"\n"));
            }
            if (Users_And_Hashes.ContainsKey(username) && temp_pass_hash == sha1)
            {
                User tUser;
                if (!users.TryGetValue(username, out tUser))
                {
                    return(new Tuple <bool, string>(false, "Error occured User is not in the users_DB but is registered: " + username + " \n"));
                }
                if (tUser.LoggedStatus())
                {
                    return(new Tuple <bool, string>(false, "The user: "******" is already logged in\n"));
                }
                tUser.LogIn();
                //Update LogginStatus
                Statistics.Instance.InserRecord(username, DateTime.Now);
                DbManager.Instance.UpdateUserLogInStatus(tUser.getUserName(), false);
                Active_users.Add(tUser.getUserName(), tUser);
                if (tUser.HasPendingMessages())
                {
                    List <NotifyData> messages = tUser.GetPendingMessages();
                    foreach (NotifyData msg in messages)
                    {
                        //Remove From DB Message
                        DbNotifyData dbMsg = DbManager.Instance.GetDbNotification(username, msg.Context);
                        DbManager.Instance.DeleteSingleMessage(dbMsg);
                        //Try to send the message and if not recieved it will be enetred to DB Again inside Notify
                        Publisher.Instance.Notify(tUser.getUserName(), msg);
                        //tUser.RemovePendingMessage(msg);
                    }
                    tUser.RemoveAllPendingMessages();
                }
                DbManager.Instance.SaveChanges();
                return(new Tuple <bool, string>(true, username + " Logged int\n"));
            }
            DbManager.Instance.SaveChanges();
            return(new Tuple <bool, string>(false, "Wrong Credentials\n"));
        }
Ejemplo n.º 3
0
        //Register regular user to the system
        //User name must be unique
        public Tuple <bool, string> Register(string username, string pass)
        {
            Logger.logSensitive(this, System.Reflection.MethodBase.GetCurrentMethod());
            Tuple <bool, string> ans = name_and_pass_check(username, pass);

            if (!ans.Item1)
            {
                return(ans);
            }

            User nUser = new User(Available_ID, username, false);

            users.Add(username, nUser);
            //insert to user to db:
            DbManager.Instance.InsertUser(AdapterUser.CreateDBUser(username, false, false, false));
            Available_ID++;

            string sha1 = SB.CalcSha1(pass);

            Users_And_Hashes.Add(username, sha1);
            DbManager.Instance.InsertPassword(AdapterUser.CreateNewPasswordEntry(username, sha1), true);
            return(new Tuple <bool, string>(true, ""));
        }
Ejemplo n.º 4
0
 //CHecks if the user is registered somewhere
 //Means the user entered username and password
 public bool isUserExist(string username)
 {
     Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod());
     //if user name exist return false
     return(Users_And_Hashes.ContainsKey(username) || users.ContainsKey(username));
 }