Exemplo n.º 1
0
        public void createUser(string login, string password, int permission_level)
        {
            string    salt     = generateSalt();
            string    hashToDb = GetSaltedHashedPassword(password, salt);
            logowanie user     = new logowanie();

            user.login            = login;
            user.hasz             = hashToDb;
            user.poziom_uprawnien = permission_level;
            user.czy_aktywny      = true;
            try {
                dc.logowanies.InsertOnSubmit(user);
                dc.SubmitChanges();
            } catch {
                MessageBox.Show("Spróbuj jeszcze raz.", "Wystąpił błąd przy tworzeniu użytkownika!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (CheckIfUserExist(login))
            {
                MessageBox.Show("Utworzono użytkownika: " + login);
            }
            else
            {
                MessageBox.Show("Spróbuj jeszcze raz.", "Wystąpił błąd przy sprawdzeniu czy użytkownik istnieje!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        public int GetPremissionLevel(string login)
        {
            logowanie data = null;

            try {
                data = dc.logowanies.Single(l => l.login == login);
            }catch (Exception e) {
                Debug.Print("Failed to get permision level from database for login: {0}\n Reason {1}", (object)login, e);
                return(0);
            }
            return(data.poziom_uprawnien);
        }
Exemplo n.º 3
0
        public bool GetUserStatus(string login)
        {
            logowanie data = null;

            try {
                data = dc.logowanies.Single(l => l.login == login);
            }catch (Exception e) {
                Debug.Print("Failed to get user account status from database for login: {0}\n Reason {1}", (object)login, e);
                return(false);
            }
            return(data.czy_aktywny);
        }
Exemplo n.º 4
0
        // Return hash from DB if login not found return 0
        // if failed to connect to db return null
        private string GetHashFromDb(string login)
        {
            logowanie data = null;

            try {
                data = dc.logowanies.Single(l => l.login == login);
            } catch (Exception e) {
                Debug.Print("Failed to get hash from database for login: {0}\n Reason: {1}", (object)login, e);
                return("0");
            }
            return(data.hasz);
        }