Esempio n. 1
0
        internal User GetUser(string username, string password)
        {
            // Gets the user from "connection"
            _database.Connection.Open();

            User user = new User();

            using (SqliteCommand cmd = _database.Connection.CreateCommand())
            {
                string sql = User.ToSqlSelectByUserName(username, password);
                cmd.CommandText = sql;

                using (SqliteDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        user.ParseToUser(reader);
                    }
                }
            }

            _database.Connection.Close();

            return user;
        }
Esempio n. 2
0
        private bool CreateAccount(string username, string password, string fullName)
        {
            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password) ||
                string.IsNullOrWhiteSpace(fullName))
            {
                return false;
            }

            //TODO: SQL/JSON injection checks

            //Check if username exists
            if (_manager.UserExists(username))
            {
                Toast.MakeText(this, "Username taken..", ToastLength.Short);
            }

            // Add new user code
            User newUser = new User(username, password, fullName);
            bool success = _manager.AddUser(newUser);

            return success;
        }
Esempio n. 3
0
        internal bool AddUser(User user)
        {
            int succeeded = 0;

            // Check for the user
            if (UserExists(user.Username))
            {
                return false;
            }

            _database.Connection.Open();

            using (SqliteCommand cmd = _database.Connection.CreateCommand())
            {
                // Insert using the iSqlite interface
                cmd.CommandText = user.ToSqlInsert();
                succeeded = cmd.ExecuteNonQuery();
            }

            _database.Connection.Close();

            return succeeded == 1;
        }