diff --git a/lib/db.js b/lib/db.js
index 2cd53f6fbd190626897418bd6805a06f660b527b..3521c2ccc4cffd5cbaaf9e75312f1d0debdb0008 100644
--- a/lib/db.js
+++ b/lib/db.js
@@ -112,7 +112,8 @@ exports.onReady = function(f) {
   'checkAuth',
   'listEmails',
   'lastStaged',
-  'ping'
+  'ping',
+  'emailType'
 ].forEach(function(fn) {
   exports[fn] = function() {
     checkReady();
@@ -130,6 +131,7 @@ exports.onReady = function(f) {
   'removeEmail',
   'cancelAccount',
   'updatePassword',
+  'createUserWithPrimaryEmail'
 ].forEach(function(fn) {
   exports[fn] = function() {
     if (!config.get('database').may_write) {
diff --git a/lib/db/json.js b/lib/db/json.js
index 18ef914b1c3358d640060eb6da2f17b3f9fc5983..3dace705a623342685f9ea58195da9a55856241e 100644
--- a/lib/db/json.js
+++ b/lib/db/json.js
@@ -127,6 +127,12 @@ exports.emailKnown = function(email, cb) {
   setTimeout(function() { cb(m.length > 0) }, 0);
 };
 
+exports.emailType = function(email, cb) {
+  sync();
+  var m = jsel.match(".emails ." + ESC(email), db.users);
+  process.nextTick(function() { cb(m.length ? m.type : undefined); });
+};
+
 exports.isStaged = function(email, cb) {
   if (cb) {
     setTimeout(function() {
@@ -201,11 +207,23 @@ exports.stageEmail = function(existing_email, new_email, cb) {
     };
     db.stagedEmails[new_email] = secret;
     flush();
-    
+
     setTimeout(function() { cb(secret); }, 0);
   });
 };
 
+exports.createUserWithPrimaryEmail = function(email, cb) {
+  var emailVal = { };
+  emailVal[email] = { type: 'primary' };
+  db.users.push({
+    password: null,
+    emails: emailVal
+  });
+  flush();
+  process.nextTick(function() {
+    cb(undefined);
+  });
+};
 
 exports.emailForVerificationSecret = function(secret, cb) {
   setTimeout(function() {
diff --git a/lib/db/mysql.js b/lib/db/mysql.js
index 2c1a608f365138c2c441d41b45be8568c94b1e99..ac93d50f4ecb5743164e1d65c6408b9c36844eb0 100644
--- a/lib/db/mysql.js
+++ b/lib/db/mysql.js
@@ -41,11 +41,12 @@
 /*
  * The Schema:
  *
- *    +--- user ------+       +--- email ----+
- *    |*int id        | <-\   |*int id       |
- *    | string passwd |    \- |*int user     |
- *    +---------------+       |*string address
- *                            +--------------+
+ *    +--- user ------+       +--- email -----+
+ *    |*int id        | <-\   |*int id        |
+ *    | string passwd |    \- |*int user      |
+ *    +---------------+       |*string address|
+ *                            | enum type     |
+ *                            +---------------+
  *
  *
  *    +------ staged ----------+
@@ -70,7 +71,7 @@ var client = undefined;
 const schemas = [
   "CREATE TABLE IF NOT EXISTS user (" +
     "id BIGINT AUTO_INCREMENT PRIMARY KEY," +
-    "passwd CHAR(64) NOT NULL" +
+    "passwd CHAR(64)" +
     ") ENGINE=InnoDB;",
 
   "CREATE TABLE IF NOT EXISTS email (" +
@@ -233,6 +234,16 @@ exports.emailKnown = function(email, cb) {
   );
 }
 
+exports.emailType = function(email, cb) {
+  client.query(
+    "SELECT type FROM email WHERE address = ?", [ email ],
+    function(err, rows) {
+      if (err) logUnexpectedError(err);
+      cb((rows && rows.length > 0) ? rows[0].type : null);
+    }
+  );
+}
+
 exports.isStaged = function(email, cb) {
   client.query(
     "SELECT COUNT(*) as N FROM staged WHERE email = ?", [ email ],
@@ -352,6 +363,23 @@ exports.gotVerificationSecret = function(secret, hash, cb) {
   );
 }
 
+exports.createUserWithPrimaryEmail = function(email, cb) {
+  // create a new user acct with no password
+  client.query(
+    "INSERT INTO user() VALUES()",
+    function(err, info) {
+      console.log(info.insertId);
+      if (err) { logUnexpectedError(err); cb(err); return; }
+      client.query(
+        "INSERT INTO email(user, address, type) VALUES(?, ?, ?)",
+        [ info.insertId, email, 'primary' ],
+        function(err, info) {
+          if (err) logUnexpectedError(err);
+          cb(err ? err : undefined);
+        });
+    });
+};
+
 exports.emailsBelongToSameAccount = function(lhs, rhs, cb) {
   client.query(
     'SELECT COUNT(*) AS n FROM email WHERE address = ? AND user = ( SELECT user FROM email WHERE address = ? );',