@tornado.gen.coroutine
    def post(self):

        # Apply canonicalizations to the passwords.
        oldpassword = self.get_argument('oldpassword', '')
        oldpassword = unicodedata.normalize('NFKC', oldpassword)
        oldpassword = oldpassword.encode()  # to UTF8 bytes
        password = self.get_argument('password', '')
        password = unicodedata.normalize('NFKC', password)
        password = password.encode()  # to UTF8 bytes
        password2 = self.get_argument('password2', '')
        password2 = unicodedata.normalize('NFKC', password2)
        password2 = password2.encode()  # to UTF8 bytes
        
        formerror = None
        formfocus = 'name'
        
        if (not oldpassword):
            formerror = 'You must enter your old password.'
            formfocus = 'oldpassword'
        elif (not password):
            formerror = 'You must enter your new password.'
            formfocus = 'password'
        elif (not password2):
            formerror = 'You must enter your new password twice.'
            formfocus = 'password2'
        elif (len(password) < 6):
            formerror = 'Please use at least six characters in your password.'
            formfocus = 'password'
        elif (len(password) > 128):
            formerror = 'Please use no more than 128 characters in your password.'
            formfocus = 'password'
        elif (password != password2):
            formerror = 'The passwords you entered were not the same.'
            password2 = ''
            formfocus = 'password2'

        if not formerror:
            try:
                res = yield self.application.twsessionmgr.find_player(self, self.twsession['email'], oldpassword)
                if not res:
                    formerror = 'Your current password does not match what you entered.'
                elif res['_id'] != self.twsession['uid']:
                    formerror = 'Your account ID did not match.'
                elif res.get('guest', None):
                    formerror = 'The guest account password cannot be changed.'
            except MessageException as ex:
                formerror = str(ex)
            
        if formerror:
            self.render('account.html', formerror=formerror,
                        name=self.twsession.get('name', '???'),
                        email=self.twsession.get('email', '???'),
                        isbuild=self.twisbuild)
            return

        try:
            yield self.application.twsessionmgr.change_password(self.twsession['uid'], password)
            # Success.
            formerror = 'Password changed.'
        except MessageException as ex:
            formerror = str(ex)

        self.render('account.html', formerror=formerror,
                    name=self.twsession.get('name', '???'),
                    email=self.twsession.get('email', '???'),
                    isbuild=self.twisbuild)
dataset/ETHPy150Open erkyrath/tworld/lib/tweblib/handlers.py/AccountHandler.post/original