Merge branch 'nopassword' into testing

This commit is contained in:
Valentin Lorentz 2021-05-25 00:12:36 +02:00
commit 1455a83391
3 changed files with 24 additions and 4 deletions

View File

@ -110,6 +110,7 @@ class User(callbacks.Plugin):
user, or use the identify command to identify just for a session. user, or use the identify command to identify just for a session.
This command (and all other commands that include a password) must be This command (and all other commands that include a password) must be
sent to the bot privately, not in a channel. sent to the bot privately, not in a channel.
Use "!" instead of <password> to disable password authentication.
""" """
addHostmask = True addHostmask = True
try: try:
@ -132,8 +133,16 @@ class User(callbacks.Plugin):
return return
except KeyError: except KeyError:
pass pass
if password == "!":
password = None
elif len(password) < 3:
irc.error(_('The password must be at least 3 characters long.'),
Raise=True)
user = ircdb.users.newUser() user = ircdb.users.newUser()
user.name = name user.name = name
if password:
user.setPassword(password) user.setPassword(password)
if addHostmask: if addHostmask:
user.addHostmask(msg.prefix) user.addHostmask(msg.prefix)

View File

@ -105,6 +105,14 @@ class UserTestCase(PluginTestCase):
m = self.irc.takeMsg() m = self.irc.takeMsg()
self.assertFalse(m is not None, m) self.assertFalse(m is not None, m)
def testRegisterPasswordLength(self):
self.assertRegexp('register foo aa', 'at least 3 characters long.')
def testRegisterNoPassword(self):
self.assertNotError('register foo !')
self.assertRegexp('identify foo bar', 'your password is wrong.')
self.assertRegexp('identify foo !', 'your password is wrong.')
def testRegisterUnregister(self): def testRegisterUnregister(self):
self.prefix = self.prefix1 self.prefix = self.prefix1
self.assertNotError('register foo bar') self.assertNotError('register foo bar')

View File

@ -252,16 +252,19 @@ class IrcUser(object):
return self.capabilities.check(capability, ignoreOwner=ignoreOwner) return self.capabilities.check(capability, ignoreOwner=ignoreOwner)
def setPassword(self, password, hashed=False): def setPassword(self, password, hashed=False):
"""Sets the user's password.""" """Sets the user's password. If password is None, it will be disabled."""
if hashed or self.hashed: if hashed or self.hashed:
self.hashed = True self.hashed = True
if password is None:
self.password = ""
else:
self.password = utils.saltHash(password) self.password = utils.saltHash(password)
else: else:
self.password = password self.password = password
def checkPassword(self, password): def checkPassword(self, password):
"""Checks the user's password.""" """Checks the user's password."""
if password is None: if password is None or not self.password:
return False return False
if self.hashed: if self.hashed:
(salt, _) = self.password.split('|') (salt, _) = self.password.split('|')