User Tools

Site Tools


rb-projects-access:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rb-projects-access:start [14/01/2025 17:37] – [Access Control] andrewrb-projects-access:start [21/02/2025 13:25] (current) – [Access Control] andrew
Line 1: Line 1:
 ====== Access Control ====== ====== Access Control ======
  
 +{{ :rb-projects-access:hid_reader_and_mifare_card.jpg?200|}}
 Very much embryonic and alpha project to play with commands which would be required to implement a electronic door lock system.  Very much embryonic and alpha project to play with commands which would be required to implement a electronic door lock system. 
  
 Key cards with a serial number are issued and each door has a Wiegand or rfid style reader, optionally requiring a PIN as well as card to unlock. Maybe bluetooth instead of PIN?  Key cards with a serial number are issued and each door has a Wiegand or rfid style reader, optionally requiring a PIN as well as card to unlock. Maybe bluetooth instead of PIN? 
  
-Also, by abstracting the keypad / reader and lock from the physical device, it should enable MQTT enabled devices to be included. If they are to be trusted..... So PKI is probably needed to maintain trust and security. (Trust but Verify!) +Also, by abstracting the keypad / reader and lock from the physical device, it should enable MQTT enabled devices to be included. If they are to be trusted..... So PKI is probably needed to maintain trust and security.  [[https://en.wikipedia.org/wiki/Trust,_but_verify| (Trust but Verify!) ]]
  
 +[[https://dbdiagram.io/d]]
  
 +[[https://www.usmartcards.co.uk/Access-control]]
 ===== Flow ===== ===== Flow =====
  
Line 16: Line 18:
  
 card id used to get user and door information from db card id used to get user and door information from db
 +<code mysql>
 -> > select userID, cardID from keycards where cardNumber = 1234; -> > select userID, cardID from keycards where cardNumber = 1234;
 +--------+--------+ +--------+--------+
Line 22: Line 25:
 |      3 |      1 | |      3 |      1 |
 +--------+--------+ +--------+--------+
 +</code>
 note cardID is an index to the table, use this as it allows a card ID to be changed if a card is lost note cardID is an index to the table, use this as it allows a card ID to be changed if a card is lost
  
  
 select door information from readerID to decide if PIN is needed. select door information from readerID to decide if PIN is needed.
 +<code mysql>
  select * from doors where readerID = 7678;  select * from doors where readerID = 7678;
 +--------+----------+-----------+---------+ +--------+----------+-----------+---------+
Line 33: Line 37:
 |      3 |     7678 | Back door |       1 | |      3 |     7678 | Back door |       1 |
 +--------+----------+-----------+---------+ +--------+----------+-----------+---------+
 +</code>
  
- +Get access level for user, I don't really like this, I need a way to record info for many users for many doors whilst remaining workable. My idea to store JSON in the SQL was a way to combine a NoSQL style db with MySQL. Seemed cool at the time..... 
-Get access level for user +<code sql> select accesslevel from access where userID = 3;
-> select accesslevel from access where userID = 3;+
 +------------------------------------------------------------+ +------------------------------------------------------------+
 | accesslevel                                                | | accesslevel                                                |
Line 46: Line 50:
 } | } |
 +------------------------------------------------------------+ +------------------------------------------------------------+
 +</code>
 so card number 1234 is cardID 1 and  userID 3. so card number 1234 is cardID 1 and  userID 3.
 presented to reader 7678 which is doorID 3 back door, as it is external it requires a PIN as well presented to reader 7678 which is doorID 3 back door, as it is external it requires a PIN as well
Line 57: Line 61:
 ===== DB structure ===== ===== DB structure =====
  
 +<code mysql>
 +show tables;
 ++-------------------------+
 +| Tables_in_accesscontrol |
 ++-------------------------+
 +| access                  |
 +| doors                   |
 +| keycards                |
 +| users                   |
 ++-------------------------+
 +23 rows in set (0.000 sec)
 +</code>
 +
 +
 +<code mysql>
 +> show create table access \G;
 +*************************** 1. row ***************************
 +       Table: access
 +Create Table: CREATE TABLE `access` (
 +  `accessID` int(11) NOT NULL,
 +  `userID` int(11) NOT NULL,
 +  `accesslevel` varchar(1024) NOT NULL,
 +  PRIMARY KEY (`accessID`),
 +  UNIQUE KEY `userID` (`userID`)
 +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
 +1 row in set (0.001 sec)
 +
 +> describe access;
 ++-------------+---------------+------+-----+---------+-------+
 +| Field       | Type          | Null | Key | Default | Extra |
 ++-------------+---------------+------+-----+---------+-------+
 +| accessID    | int(11)       | NO   | PRI | NULL    |       |
 +| userID      | int(11)       | NO   | UNI | NULL    |       |
 +| accesslevel | varchar(1024) | NO       | NULL    |       |
 ++-------------+---------------+------+-----+---------+-------+
 +
 +</code>
 +
 +
 +<code mysql>
 +show create table doors \G;
 +*************************** 1. row ***************************
 +       Table: doors
 +Create Table: CREATE TABLE `doors` (
 +  `doorID` int(11) NOT NULL AUTO_INCREMENT,
 +  `readerID` int(11) NOT NULL,
 +  `doorDesc` varchar(255) NOT NULL,
 +  `pinReqd` tinyint(1) NOT NULL,
 +  PRIMARY KEY (`doorID`),
 +  UNIQUE KEY `doorDesc` (`doorDesc`)
 +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
 +1 row in set (0.000 sec)
 +
 +> describe doors;
 ++----------+--------------+------+-----+---------+----------------+
 +| Field    | Type         | Null | Key | Default | Extra          |
 ++----------+--------------+------+-----+---------+----------------+
 +| doorID   | int(11)      | NO   | PRI | NULL    | auto_increment |
 +| readerID | int(11)      | NO       | NULL    |                |
 +| doorDesc | varchar(255) | NO   | UNI | NULL    |                |
 +| pinReqd  | tinyint(1)   | NO       | NULL    |                |
 ++----------+--------------+------+-----+---------+----------------+
 +
 +</code>
 +
 +
 +<code mysql>
 +show create table keycards \G;
 +*************************** 1. row ***************************
 +       Table: keycards
 +Create Table: CREATE TABLE `keycards` (
 +  `cardID` int(11) NOT NULL,
 +  `cardNumber` varchar(256) NOT NULL,
 +  `Created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 +  `Deleted` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
 +  `userID` int(11) NOT NULL,
 +  PRIMARY KEY (`cardID`)
 +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
 +1 row in set (0.000 sec)
 +
 +
 +> describe keycards;
 ++------------+--------------+------+-----+---------------------+-------------------------------+
 +| Field      | Type         | Null | Key | Default             | Extra                         |
 ++------------+--------------+------+-----+---------------------+-------------------------------+
 +| cardID     | int(11)      | NO   | PRI | NULL                |                               |
 +| cardNumber | varchar(256) | NO       | NULL                |                               |
 +| Created    | timestamp    | NO       | current_timestamp() | on update current_timestamp() |
 +| Deleted    | timestamp    | NO       | 0000-00-00 00:00:00 |                               |
 +| userID     | int(11)      | NO       | NULL                |                               |
 ++------------+--------------+------+-----+---------------------+-------------------------------+
 +
 +</code>
 +
 +
 +<code mysql>
 +show create table users \G;
 +*************************** 1. row ***************************
 +       Table: users
 +Create Table: CREATE TABLE `users` (
 +  `userID` int(11) NOT NULL,
 +  `username` varchar(256) NOT NULL,
 +  `firstname` varchar(256) NOT NULL,
 +  `surname` varchar(256) NOT NULL,
 +  `pin` int(11) NOT NULL,
 +  `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
 +  `deleted` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
 +  PRIMARY KEY (`userID`)
 +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
 +1 row in set (0.001 sec)
 +
 +
 + describe users;
 ++-----------+--------------+------+-----+---------------------+-------------------------------+
 +| Field     | Type         | Null | Key | Default             | Extra                         |
 ++-----------+--------------+------+-----+---------------------+-------------------------------+
 +| userID    | int(11)      | NO   | PRI | NULL                |                               |
 +| username  | varchar(256) | NO       | NULL                |                               |
 +| firstname | varchar(256) | NO       | NULL                |                               |
 +| surname   | varchar(256) | NO       | NULL                |                               |
 +| pin       | int(11)      | NO       | NULL                |                               |
 +| created   | timestamp    | NO       | current_timestamp() | on update current_timestamp() |
 +| deleted   | timestamp    | NO       | 0000-00-00 00:00:00 |                               |
 ++-----------+--------------+------+-----+---------------------+-------------------------------+
 +
 +</code>
  
  
rb-projects-access/start.1736876230.txt.gz · Last modified: by andrew

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki