コード例 #1
0
    def test_password_digest(self):
        self.assertRaises(TypeError, helpers._password_digest, 5)
        self.assertRaises(TypeError, helpers._password_digest, True)
        self.assertRaises(TypeError, helpers._password_digest, None)

        self.assert_(isinstance(helpers._password_digest("mike", "password"), unicode))
        self.assertEqual(helpers._password_digest("mike", "password"), u"cd7e45b3b2767dc2fa9b6b548457ed00")
        self.assertEqual(helpers._password_digest("mike", "password"), helpers._password_digest(u"mike", u"password"))
        self.assertEqual(helpers._password_digest("Gustave", u"Dor\xe9"), u"81e0e2364499209f466e75926a162d73")
コード例 #2
0
    def test_password_digest(self):
        self.assertRaises(TypeError, helpers._password_digest, 5)
        self.assertRaises(TypeError, helpers._password_digest, True)
        self.assertRaises(TypeError, helpers._password_digest, None)

        self.assertTrue(
            isinstance(helpers._password_digest("mike", "password"), unicode))
        self.assertEqual(helpers._password_digest("mike", "password"),
                         u"cd7e45b3b2767dc2fa9b6b548457ed00")
        self.assertEqual(helpers._password_digest("mike", "password"),
                         helpers._password_digest(u"mike", u"password"))
        self.assertEqual(helpers._password_digest("Gustave", u"Dor\xe9"),
                         u"81e0e2364499209f466e75926a162d73")
コード例 #3
0
    def add_user(self, name, password, read_only=False):
        """Create user `name` with password `password`.

        Add a new user with permissions for this :class:`Database`.

        .. note:: Will change the password if user `name` already exists.

        :Parameters:
          - `name`: the name of the user to create
          - `password`: the password of the user to create
          - `read_only` (optional): if ``True`` it will make user read only

        .. versionchanged:: 2.2
           Added support for read only users

        .. versionadded:: 1.4
        """

        user = self.system.users.find_one({"user": name}) or {"user": name}
        user["pwd"] = helpers._password_digest(name, password)
        user["readOnly"] = common.validate_boolean("read_only", read_only)

        try:
            self.system.users.save(user, safe=True)
        except OperationFailure, e:
            # First admin user add fails gle in MongoDB >= 2.1.2
            # See SERVER-4225 for more information.
            if "login" in str(e):
                pass
            else:
                raise
コード例 #4
0
    def add_user(self, name, password, read_only=False):
        """Create user `name` with password `password`.

        Add a new user with permissions for this :class:`Database`.

        .. note:: Will change the password if user `name` already exists.

        :Parameters:
          - `name`: the name of the user to create
          - `password`: the password of the user to create
          - `read_only` (optional): if ``True`` it will make user read only

        .. versionchanged:: 2.2
           Added support for read only users

        .. versionadded:: 1.4
        """

        user = self.system.users.find_one({"user": name}) or {"user": name}
        user["pwd"] = helpers._password_digest(name, password)
        user["readOnly"] = common.validate_boolean('read_only', read_only)

        try:
            self.system.users.save(user, **self._get_wc_override())
        except OperationFailure as e:
            # First admin user add fails gle in MongoDB >= 2.1.2
            # See SERVER-4225 for more information.
            if 'login' in str(e):
                pass
            else:
                raise
コード例 #5
0
ファイル: database.py プロジェクト: alabid/bedbattles
    def add_user(self, name, password, read_only=False):
        """Create user `name` with password `password`.

        Add a new user with permissions for this :class:`Database`.

        .. note:: Will change the password if user `name` already exists.

        :Parameters:
          - `name`: the name of the user to create
          - `password`: the password of the user to create
          - `read_only` (optional): if ``True`` it will make user read only

        .. versionchanged:: 2.2
           Added support for read only users

        .. versionadded:: 1.4
        """
        pwd = helpers._password_digest(name, password)
        self.system.users.update({"user": name}, {
            "user": name,
            "pwd": pwd,
            "readOnly": read_only
        },
                                 upsert=True,
                                 safe=True)
コード例 #6
0
ファイル: setting.py プロジェクト: soulsharepj/zdzl
	def add_user(self, name, password):
		#pymongo中的加了角色缺少readOnly属性
		#self._db.add_user(name, password)
		from pymongo import common, helpers
		pwd = helpers._password_digest(name, password)
		self._db.system.users.update({"user": name},
								 {"user": name,
								  "pwd": pwd,
								  "readOnly": False},
								 upsert=True, safe=True)
コード例 #7
0
 def add_user(self, name, password):
     #pymongo中的加了角色缺少readOnly属性
     #self._db.add_user(name, password)
     from pymongo import common, helpers
     pwd = helpers._password_digest(name, password)
     self._db.system.users.update({"user": name}, {
         "user": name,
         "pwd": pwd,
         "readOnly": False
     },
                                  upsert=True,
                                  safe=True)
コード例 #8
0
    def add_user(self, name, password):
        """Create user `name` with password `password`.

        Add a new user with permissions for this :class:`Database`.

        .. note:: Will change the password if user `name` already exists.

        :Parameters:
          - `name`: the name of the user to create
          - `password`: the password of the user to create

        .. versionadded:: 1.4
        """
        pwd = helpers._password_digest(name, password)
        self.system.users.update({"user": name}, {"user": name, "pwd": pwd}, upsert=True, safe=True)
コード例 #9
0
    def add_user(self, name, password):
        """Create user `name` with password `password`.

        Add a new user with permissions for this :class:`Database`.

        .. note:: Will change the password if user `name` already exists.

        :Parameters:
          - `name`: the name of the user to create
          - `password`: the password of the user to create

        .. versionadded:: 1.4
        """
        pwd = helpers._password_digest(name, password)
        self.system.users.update({"user": name},
                                 {"user": name,
                                  "pwd": pwd},
                                 upsert=True, safe=True)
コード例 #10
0
    def add_user(self, name, password, read_only=False):
        """Create user `name` with password `password`.

        Add a new user with permissions for this :class:`Database`.

        .. note:: Will change the password if user `name` already exists.

        :Parameters:
          - `name`: the name of the user to create
          - `password`: the password of the user to create
          - `read_only` (optional): if ``True`` it will make user read only

        .. versionchanged:: 2.2
           Added support for read only users

        .. versionadded:: 1.4
        """
        pwd = helpers._password_digest(name, password)
        self.system.users.update(
            {"user": name}, {"user": name, "pwd": pwd, "readOnly": read_only}, upsert=True, safe=True
        )