Tip: Because the project is a little bit large for me personally, so may be in some aspects of unclear or logic is not strong enough, if there is a problem please timely @ me.
Original project: https://github.com/LineChen/
First, registration
Registration is to save the user's personal information, including the user registration mailbox, the system assigned ID (at first did not think of the allocation ID to identify a user, but to prepare to use the mailbox, but in the Save user offline message needs to combine the user unique identification to create the table, because the mailbox with special characters @, so it cannot be used as the table name Only one ID is assigned to each registered user, then all communication operations are identified by ID), user name, birthday, gender, password, avatar
Note the point:
1. Avatar storage: Here is not the Avatar with blob-type data to the database, but with the help of the file system to save the user's avatar, including the following offline voice and offline images, in the database only save the path, so easy to operate, faster. All other and picture or voice related processing is the same as this.
2. Password storage: For the various operation of the password, we must try to ensure the maximum safety degree. Between the client and server delivery, the use of PBE symmetric encryption, if no one dedicated to take the time to catch the packet decryption, and even if this can not be decrypted. Then, for passwords, such as registration, or login to use the password, sent to the server password is MD5 conversion, that is, in the database storage password is not plaintext storage, in clear text store password is a very dangerous practice. If someone steals your database, it also gets all the information from the user, including the password. Remember the previous years of "password event", CSDN user database leaks, Tianya database leaks, sony database leaks, etc., involving the user is tens of millions of, the tragedy is Tianya storage user's information is all clear text, including password ...
/**
* Process Registration
*
* @param session
* Session
* @param momsg
* Message Pack
*/
public void Handleregister (iosession session, Imomomsg momomsg) {
Jsonobject json = Json.parseobject (Momomsg.msgjson);
Sqlmodel model = new Sqlmodel ();
String useremail = json.getstring (Msgkeys.useremail);
String userId = Model.allocateid ();//Assignment ID
String Userheadpath = staticvalues.head_p_path + userId + ". png";
Filetools.getinstance (). Savemultyfile (Userheadpath, momomsg.msgbytes);
String sql = "INSERT into imomo_clients values (?,?,?,?,?,?,?,?,?)";
String[] Paras = {userId, useremail, json.getstring (Msgkeys.username),
Json.getstring (MSGKEYS.USERPASSWD), Userheadpath,
Json.getstring (Msgkeys.usersex),
Json.getstring (Msgkeys.userbirthday), "", 0+ ""};
Imomomsg Notify = new Imomomsg ();
Notify.symbol = ' + ';
Jsonobject Notifyjson = new Jsonobject ();
if (Model.updatedb (SQL, paras)) {
Notifyjson.put (Msgkeys.msgtype, imomomsgtypes.register_success);
SYSTEM.OUT.PRINTLN ("registered success");
} else {
Notifyjson.put (Msgkeys.msgtype, imomomsgtypes.register_failed);//Registration failed
}
Notify.msgjson = Notifyjson.tojsonstring ();
Session.write (Notify);
}
From the above you can see that the registration is divided into assigning user IDs and then saving personal information. The success of the Save is successful registration, the notification to send a successful registration to the user.
Deciphering Strangers (7) Register