MongoDB Security Authentication and PHP security Processing

Source: Internet
Author: User
Tags mongodb client mongodb server

MongoDB official explanation of Security Verification:

Http://www.mongodb.org/display/DOCS/Security+and+Authentication

In MongoDB, Service Startup does not have permission verification by default. In terms of security, this is definitely not feasible. Therefore, you need to add permission verification.

To verify permissions, you must have a user. Therefore, the first step of permission verification is to add users to the MongoDB database.

Start the MongoDB server, start the MongoDB client, and add users to the MongoDB database using commands on the client. See the Code:


> db.addUser("jiangzhichao","jzc19880316");{        "user" :"jiangzhichao",        "readOnly" :false,        "pwd" :"f7559cfe0bc0a305f82c0d83664538fd"}

TIPS:Adding users to the admin database is global, that is, adding users to the admin database is also applicable to other databases.

To add permission verification to the MongoDB server, you must add the -- auth parameter when starting the MongoDB service. The Code is as follows:

D: \ MongoDB \ bin> mongod -- dbpath D: \ MongoDB \ data -- logpath D: \ MongoDB \ log \ MongoDB. log -- logappend -- servicename MongoDB -- auth -- installall output going to: D: \ MongoDB \ log \ MongoDB. logcreating service MongoDB. service creation successful. service can be started from the command line via 'net start "MongoDB "'. d: \ MongoDB \ bin> Net start "MongoDB" mongo dB service is starting. the Mongo dB service has been started successfully.

Here I start the MongoDB service as a Service. The first command is to install the service, and the second command is to start the service.

The services have been started, and the client is opened. This is simple. Check the Code:

d:\mongodb\bin>mongoMongoDB shell version: 1.8.2connecting to: test> show dbs;Mon Oct 24 21:54:13 uncaught exception: listDatabases failed:{        "assertion" :"unauthorized db:admin lock type:-1 client:127.0.0.1",        "assertionCode" : 10057,        "errmsg" :"db assertion failure",        "ok" : 0}

The show DBS Command reports an exception. Check the exception details. Unauthorized DB: Admin lock. The permission cannot be verified.

Logging in as an admin userAlthough admin user accounts can access any database, you must log into the admin database. For example, if someAdminUser has an admin account, this login will succeed: > use admin> db.auth("someAdminUser", password)> // and then if desired switch databases:> use test

Ah!

Well, the following is the permission verification. Here, I am nagging about it. During permission verification, I quit the client first or start another client. The Code is as follows:

d:\mongodb\bin>mongo admin -u jiangzhichao -p jzc19880316MongoDB shell version: 1.8.2connecting to: admin> show dbs;admin   0.078125GBlocal   (empty)test    (empty)

Command Format: Mongo [database name]-U [user name]-P [Password]

The show DBS above can be executed and the result is displayed.

At this point, the permission verification process is complete.

PHP officially provides a complete description of MongoDB's secure PHP processing.

Http://php.net/manual/zh/mongo.security.php

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.