2009-11-17 14:30:02 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
|
2009-11-18 08:14:53 +00:00
|
|
|
<!-- $Revision$ -->
|
2009-11-17 14:30:02 +00:00
|
|
|
<refentry xml:id="mongodb.authenticate" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
|
|
<refnamediv>
|
|
|
|
<refname>MongoDB::authenticate</refname>
|
|
|
|
<refpurpose>Log in to this database</refpurpose>
|
|
|
|
</refnamediv>
|
2016-02-22 16:53:35 +00:00
|
|
|
|
|
|
|
<refsynopsisdiv role="soft-deprecation-notice">
|
|
|
|
<sidebar>
|
|
|
|
&mongo.noalternative.method.note;
|
|
|
|
<para>Instead, you need to provide credentials through the connection
|
|
|
|
string.</para>
|
|
|
|
</sidebar>
|
|
|
|
</refsynopsisdiv>
|
|
|
|
|
2009-11-17 14:30:02 +00:00
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
|
|
|
<methodsynopsis>
|
|
|
|
<modifier>public</modifier> <type>array</type><methodname>MongoDB::authenticate</methodname>
|
|
|
|
<methodparam><type>string</type><parameter>username</parameter></methodparam>
|
|
|
|
<methodparam><type>string</type><parameter>password</parameter></methodparam>
|
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
2012-11-26 03:07:28 +00:00
|
|
|
This method causes its connection to be authenticated. If authentication is
|
|
|
|
enabled for the database server (it's not, by default), you need to log in
|
2009-11-17 14:30:02 +00:00
|
|
|
before the database will allow you to do anything.
|
|
|
|
</para>
|
2010-08-04 19:01:27 +00:00
|
|
|
<para>
|
2012-11-26 03:07:28 +00:00
|
|
|
In general, you should use the authenticate built into
|
|
|
|
<function>MongoClient::__construct</function> in preference to this method.
|
|
|
|
If you authenticate on connection and the connection drops and reconnects
|
|
|
|
during your session, you'll be reauthenticated. If you manually
|
|
|
|
authenticated using this method and the connection drops, you'll have to call
|
|
|
|
this method again once you're reconnected.
|
2010-08-04 19:01:27 +00:00
|
|
|
</para>
|
2010-01-28 17:35:41 +00:00
|
|
|
<para>
|
|
|
|
This method is identical to running:
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
|
|
|
|
$salted = "${username}:mongo:${password}";
|
|
|
|
$hash = md5($salted);
|
|
|
|
|
|
|
|
$nonce = $db->command(array("getnonce" => 1));
|
|
|
|
|
|
|
|
$saltedHash = md5($nonce["nonce"]."${username}${hash}");
|
|
|
|
|
2012-11-26 03:07:28 +00:00
|
|
|
$result = $db->command(array("authenticate" => 1,
|
2010-01-28 17:35:41 +00:00
|
|
|
"user" => $username,
|
|
|
|
"nonce" => $nonce["nonce"],
|
2010-07-09 11:28:40 +00:00
|
|
|
"key" => $saltedHash
|
|
|
|
));
|
2010-01-28 17:35:41 +00:00
|
|
|
|
2010-02-25 16:22:04 +00:00
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
<para>
|
2012-11-26 03:07:28 +00:00
|
|
|
Once a connection has been authenticated, it can only be un-authenticated by
|
2010-02-25 16:22:04 +00:00
|
|
|
using the "logout" database command:
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
|
|
|
|
$db->command(array("logout" => 1));
|
|
|
|
|
2010-01-28 17:35:41 +00:00
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
2009-11-17 14:30:02 +00:00
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
|
|
|
<para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>
|
|
|
|
<parameter>username</parameter>
|
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The username.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2012-11-26 03:07:28 +00:00
|
|
|
</varlistentry>
|
2009-11-17 14:30:02 +00:00
|
|
|
<varlistentry>
|
|
|
|
<term>
|
|
|
|
<parameter>password</parameter>
|
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The password (in plaintext).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2012-11-26 03:07:28 +00:00
|
|
|
</varlistentry>
|
2009-11-17 14:30:02 +00:00
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
2012-11-26 03:07:28 +00:00
|
|
|
&reftitle.returnvalues;
|
2009-11-17 14:30:02 +00:00
|
|
|
<para>
|
2010-02-24 15:06:34 +00:00
|
|
|
Returns database response. If the login was successful, it will return
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
2010-07-09 09:38:38 +00:00
|
|
|
<?php
|
|
|
|
array("ok" => 1);
|
|
|
|
?>
|
2010-02-24 15:06:34 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
If something went wrong, it will return
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
2010-07-09 09:38:38 +00:00
|
|
|
<?php
|
|
|
|
array("ok" => 0, "errmsg" => "auth fails");
|
|
|
|
?>
|
2010-02-24 15:06:34 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
("auth fails" could be another message, depending on database version and what
|
|
|
|
when wrong).
|
2009-11-17 14:30:02 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
2010-02-11 16:37:10 +00:00
|
|
|
|
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
|
|
|
<para>
|
|
|
|
MongoDB core docs on <link xlink:href="&url.mongodb.dochub.authenticate;">authenticate</link>.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
2012-07-19 16:57:19 +00:00
|
|
|
|
|
|
|
<refsect1 role="changelog">
|
|
|
|
&reftitle.changelog;
|
|
|
|
<para>
|
|
|
|
<informaltable>
|
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>&Version;</entry>
|
|
|
|
<entry>&Description;</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>1.2.11</entry>
|
|
|
|
<entry>
|
2012-10-05 20:22:15 +00:00
|
|
|
Emits <constant>E_DEPRECATED</constant> when used. Please pass in the
|
|
|
|
authentication details to the constructor.
|
2012-07-19 16:57:19 +00:00
|
|
|
</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</informaltable>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
2009-11-17 14:30:02 +00:00
|
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
2012-11-26 03:07:28 +00:00
|
|
|
-->
|