OSDN Git Service

md5でパスワードを暗号化するようにした
authorkonekoneko <jbh03215@hotmail.co.jp>
Thu, 22 Nov 2012 13:30:56 +0000 (22:30 +0900)
committerkonekoneko <jbh03215@hotmail.co.jp>
Thu, 22 Nov 2012 13:30:56 +0000 (22:30 +0900)
init.sql
profile.js
public/profile/edit.ejs

index 6befa87..058468c 100644 (file)
--- a/init.sql
+++ b/init.sql
@@ -15,7 +15,7 @@ CREATE TABLE list(
        weight SMALLINT  UNSIGNED DEFAULT 0,
        gender VARCHAR(8),
        race VARCHAR(64),
-       password VARCHAR(16),
+       password VARCHAR(32),
        etc TEXT,
        PRIMARY KEY(name_hash));
 
index 699d9f8..15547b3 100644 (file)
@@ -207,8 +207,11 @@ function edit_postproc(req, res)
        }else if(typeof(req.body.edit) != "undefined"){\r
                async.waterfall([\r
                        function(cb){\r
-                               collection.UpdatAsync(req.body.name,req.body,cb);\r
-                       }\r
+                               if(req.body.updatepw == false)\r
+                                       collection.UpdatAsync(req.body.name,req.body,null,cb);\r
+                               else\r
+                                       collection.UpdatAsync(req.body.name,req.body,req.body.password,cb);\r
+                       },\r
                ],function(err,result){\r
                        if(err != null)\r
                                RenderMessage(res,err,req.session.items);\r
@@ -279,7 +282,7 @@ function ProfileCollection()
                                pool.query("SELECT * FROM list WHERE name_hash = ? and name = ?",[murmurhash.v3(name),name],next);\r
                        },\r
                        function(result,next){\r
-                               if(result[0].password == password)\r
+                               if(result[0].password == md5_hex(password))\r
                                        next(null,true);\r
                                else\r
                                        next(null,false);\r
@@ -298,13 +301,13 @@ function ProfileCollection()
                        height:data.height,\r
                        weight:data.weight,\r
                        race:data.race,\r
-                       password:data.password,\r
+                       password:md5_hex(data.password),\r
                        lastmodified:new Date(),\r
                        etc:data.etc\r
                };\r
                pool.query("INSERT INTO list SET ?",[item],cb);\r
        }\r
-       this.UpdatAsync = function(name,data,cb){\r
+       this.UpdatAsync = function(name,data,newpassword,cb){\r
                var item = {\r
                        name_hash:murmurhash.v3(data.name),\r
                        name:data.name,\r
@@ -313,10 +316,11 @@ function ProfileCollection()
                        height:data.height,\r
                        weight:data.weight,\r
                        race:data.race,\r
-                       password:data.password,\r
                        lastmodified:new Date(),\r
                        etc:data.etc\r
                };\r
+               if(newpassword != null)\r
+                       item.password = md5_hex(newpassword);\r
                pool.query("UPDATE list SET ? WHERE name = ?",[item,name],cb);\r
        }\r
        this.ClearAsync = function(cb){\r
@@ -334,5 +338,13 @@ function ProfileCollection()
        this.ToArrayAsync = function(start,count,cb){\r
                pool.query("SELECT name,age,lastmodified FROM list LIMIT ?,?",[start,count],cb);\r
        }\r
+\r
+       var crypto = require("crypto");\r
+       function md5_hex(src)\r
+       {\r
+               var md5 = crypto.createHash('md5');\r
+               md5.update(src, 'utf8');\r
+       return md5.digest('hex');\r
+       }\r
 }\r
 \r
index bddf594..cf4a4f0 100644 (file)
                        </tr>\r
                        <tr>\r
                                <td>パスワード</td>\r
-                               <td><input type="text" value="<%=list[0].password %>" name="password"/></td>\r
+                               <td>\r
+                                       <input type="text" value="" name="password"/><br/>\r
+                                       <input type="checkbox" name="updatepw" value="true">パスワードを更新する</input>\r
+                               </td>\r
                        </tr>\r
                        <tr>\r
                                <td>年齢</td>\r