Ferreteria/sql/user account: Difference between revisions

From Woozle Writes Code
Jump to navigation Jump to search
m (Woozle moved page VbzCart/tables/user to Ferreteria/sql/user account without leaving a redirect: this is (now) actually a ferreteria table)
(post-move adjustments)
Line 10: Line 10:
* '''2013-11-09''' renamed from '''core_users''' to '''user'''
* '''2013-11-09''' renamed from '''core_users''' to '''user'''
* '''2013-12-26''' (1) we need the email address too; (2) making UserName a unique key
* '''2013-12-26''' (1) we need the email address too; (2) making UserName a unique key
* '''2017-01-26''' moved to Ferreteria, renamed "user_account", switched from MYISAM to INNODB; made "WhenCreated" NOT NULL
===Fields===
===Fields===
* '''PassSalt''': random data prepended to the password before hashing in order to prevent [[wikipedia:rainbow table|precomputed lookup]] attacks if any hashed passwords are revealed (e.g. if the database is cracked)
* '''PassSalt''': random data prepended to the password before hashing in order to prevent [[wikipedia:rainbow table|precomputed lookup]] attacks if any hashed passwords are revealed (e.g. if the database is cracked)
Line 16: Line 17:
* '''EmailAddr''': email address, for resetting password on existing account; see RFC 3696 for length  
* '''EmailAddr''': email address, for resetting password on existing account; see RFC 3696 for length  
==SQL==
==SQL==
<mysql>CREATE TABLE `user` (
<mysql>CREATE TABLE `user_account` (
   `ID`          INT              NOT NULL AUTO_INCREMENT,
   `ID`          INT              NOT NULL AUTO_INCREMENT,
   `UserName`    VARCHAR(31)      NOT NULL COMMENT "log in ID",
   `UserName`    VARCHAR(31)      NOT NULL COMMENT "log in ID",
Line 23: Line 24:
   `PassSalt`    VARBINARY(128)  NOT NULL COMMENT "random prefix for hashing password",
   `PassSalt`    VARBINARY(128)  NOT NULL COMMENT "random prefix for hashing password",
   `EmailAddr`    VARCHAR(255)    NOT NULL COMMENT "email address",
   `EmailAddr`    VARCHAR(255)    NOT NULL COMMENT "email address",
   `WhenCreated`  DATETIME                 COMMENT "when user was created",
   `WhenCreated`  DATETIME         NOT NULL COMMENT "when user was created",
   UNIQUE KEY(`UserName`),
   UNIQUE KEY(`UserName`),
   PRIMARY KEY(`ID`)
   PRIMARY KEY(`ID`)
)
)
ENGINE = MYISAM;</mysql>
ENGINE = INNODB;</mysql>

Revision as of 00:27, 27 January 2017

About

  • Purpose: tracks site users as a separate concept from customers. A user may or may not be a customer; a customer only becomes a user if they select a login ID. Later, users might also be admins or vendors.
  • Used by: user_x_ugroup

Rules

  • A user may have zero or more customers; a customer may have one user or none. This was initially done as a quick way to implement users within the existing structure; we'll have to decide later if it makes sense -- but it does seem to offer some advantages to the users.
  • When checking out, a logged-in user has the option of choosing to use shipping and payment data from their existing customer records or entering new data for either (which will then be added as a new customer record).
  • If the user is not logged in, new customer records (with no user ID) will be added regardless.

History

  • 2013-09-25 initial design
  • 2013-11-09 renamed from core_users to user
  • 2013-12-26 (1) we need the email address too; (2) making UserName a unique key
  • 2017-01-26 moved to Ferreteria, renamed "user_account", switched from MYISAM to INNODB; made "WhenCreated" NOT NULL

Fields

  • PassSalt: random data prepended to the password before hashing in order to prevent precomputed lookup attacks if any hashed passwords are revealed (e.g. if the database is cracked)
    • One source advised that the salt should have at least as many bits as the hash result, which makes sense.
    • "Whirlpool" seems to be among the best of the hash algorithms available in PHP. Blowfish or bcrypt would be better, but availability is iffy.
  • EmailAddr: email address, for resetting password on existing account; see RFC 3696 for length

SQL

<mysql>CREATE TABLE `user_account` (

 `ID`           INT              NOT NULL AUTO_INCREMENT,
 `UserName`     VARCHAR(31)      NOT NULL COMMENT "log in ID",
 `FullName`     VARCHAR(127) DEFAULT NULL COMMENT "optional 'real' name",
 `PassHash`     VARBINARY(128)   NOT NULL COMMENT "hash for [password+salt]",
 `PassSalt`     VARBINARY(128)   NOT NULL COMMENT "random prefix for hashing password",
 `EmailAddr`    VARCHAR(255)     NOT NULL COMMENT "email address",
 `WhenCreated`  DATETIME         NOT NULL COMMENT "when user was created",
 UNIQUE KEY(`UserName`),
 PRIMARY KEY(`ID`)

) ENGINE = INNODB;</mysql>