Skip to content

Commit

Permalink
Merge pull request #116 from pliablepixels/api-tokens
Browse files Browse the repository at this point in the history
support for bcrypt
  • Loading branch information
pliablepixels committed May 24, 2019
2 parents 326a4f7 + 135ff36 commit c5a8311
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 23 deletions.
34 changes: 18 additions & 16 deletions docs/guides/hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ Limitations
~~~~~~~~~~~

- Only tested with ZM 1.32+. May or may not work with older versions
- Tested with Python3. Should also work with Python2, but you should know,
- Needs Python3 (I used to support Python2, but not any more)
Python2 will be deprecated in 2020. May as well update.
- If you are using Python3, you can use ``python`` and ``pip``. They will point to python3 versions. You typically need to use ``python3`` and ``pip3`` when you have a mixed Python 2.x and 3.x install


What
~~~~
Expand All @@ -40,8 +42,8 @@ Installation
Option 1: Automatic install
^^^^^^^^^^^^^^^^^^^^^^^^^^^

- You need to have ``pip`` installed. On ubuntu, it is
``sudo apt install python-pip``, or see
- You need to have ``pip3`` installed. On ubuntu, it is
``sudo apt install python3-pip``, or see
`this <https://pip.pypa.io/en/stable/installing/>`__
- Clone the event server and go to the ``hook`` directory

Expand All @@ -65,19 +67,19 @@ Option 1: Automatic install
::

sudo apt-get install libopenblas-dev liblapack-dev libblas-dev # not mandatory, but gives a good speed boost!
sudo -H pip install face_recognition # mandatory
sudo -H pip3 install face_recognition # mandatory

Takes a while and installs a gob of stuff, which is why I did not add it
automatically, especially if you don't need face recognition.

Note, if you installed ``face_recognition`` without blas, do this:

::
sudo -H pip uninstall dlib
sudo -H pip uninstall face-recognition
sudo -H pip3 uninstall dlib
sudo -H pip3 uninstall face-recognition
sudo apt-get install libopenblas-dev liblapack-dev libblas-dev # this is the important part
sudo -H pip install dlib --verbose --no-cache-dir # make sure it finds openblas
sudo -H pip install face_recognition
sudo -H pip3 install dlib --verbose --no-cache-dir # make sure it finds openblas
sudo -H pip3 install face_recognition

Option 2: Manual install
^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -93,32 +95,32 @@ If automatic install fails for you, or you like to be in control:

.. code:: bash
sudo -H pip install -r hook/requirements.txt
sudo -H pip3 install -r hook/requirements.txt
- Install object detection files:

.. code:: bash
sudo -H pip install hook
sudo -H pip3 install hook
**Note:** if you want to add "face recognition" you also need to do

::

sudo apt-get install libopenblas-dev liblapack-dev libblas-dev # not mandatory, but gives a good speed boost!
sudo -H pip install face_recognition # mandatory
sudo -H pip3 install face_recognition # mandatory

Takes a while and installs a gob of stuff, which is why I did not add it
automatically, especially if you don't need face recognition.

Note, if you installed ``face_recognition`` without blas, do this:

::
sudo -H pip uninstall dlib
sudo -H pip uninstall face-recognition
sudo -H pip3 uninstall dlib
sudo -H pip3 uninstall face-recognition
sudo apt-get install libopenblas-dev liblapack-dev libblas-dev # this is the important part
sudo -H pip install dlib --verbose --no-cache-dir # make sure it finds openblas
sudo -H pip install face_recognition
sudo -H pip3 install dlib --verbose --no-cache-dir # make sure it finds openblas
sudo -H pip3 install face_recognition


- You now need to download configuration and weight files that are
Expand Down Expand Up @@ -276,7 +278,7 @@ How to use face recognition
Face Recognition uses
`this <https://github.com/ageitgey/face_recognition>`__ library. Before
you try and use face recognition, please make sure you did a
``sudo -H pip install face_recognition`` The reason this is not
``sudo -H pip3 install face_recognition`` The reason this is not
automatically done during setup is that it installs a lot of
dependencies that takes time (including dlib) and not everyone wants it.

Expand Down
14 changes: 11 additions & 3 deletions docs/guides/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ to get into the CPAN shell and install it from the shell as a 2 step
process. You'd do that using ``sudo perl -MCPAN -e shell`` and then
whilst inside the shell, ``install Module::Name``)

- Crypt::MySQL
- Crypt::MySQL (if you have updated to ZM 1.34, this is no longer needed)
- Net::WebSocket::Server
- Config::IniFiles (you may already have this installed)
- Crypt::Eksblowfish::Bcrypt (if you have updated to ZM 1.34, you will already have this)

Installing these dependencies is as simple as:

::

perl -MCPAN -e "install Crypt::MySQL"
perl -MCPAN -e "install Config::IniFiles"
sudo perl -MCPAN -e "install Crypt::MySQL"
sudo perl -MCPAN -e "install Config::IniFiles"
sudo perl -MCPAN -e "install Crypt::Eksblowfish::Bcrypt"

If after installing them you still see errors about these libraries
missing, please launch a CPAN shell - see General Note above.
Expand All @@ -50,6 +52,12 @@ aaronl)
::

sudo apt-get install libcrypt-mysql-perl
If you face issues installing Crypt::Eksblowfish::Bcrypt, this this instead:

::
sudo apt-get install libcrypt-eksblowfish-perl


If there are issues installing Config::IniFiles and the errors are
related to Module::Build missing, use following command to get this
Expand Down
25 changes: 21 additions & 4 deletions zmeventnotification.pl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@
if (!try_use ("Getopt::Long")) {Fatal ("Getopt::Long missing");}
if (!try_use ("File::Basename")) {Fatal ("File::Basename missing");}
if (!try_use ("File::Spec")) {Fatal ("File::Spec missing");}
if (!try_use ("Crypt::MySQL qw(password password41)")) {Fatal ("Crypt::MySQL missing");}

#if (!try_use ("threads")) {Fatal ("threads library/support missing");}

Expand Down Expand Up @@ -750,9 +749,27 @@ sub validateZmAuth
or Fatal( "Can't execute: ".$sth->errstr() );
if (my ($state) = $sth->fetchrow_hashref())
{
my $encryptedPassword = password41($p);
$sth->finish();
return $state->{Password} eq $encryptedPassword ? 1:0;
my $scheme = substr($state->{Password}, 0, 1);
if ($scheme eq "*") { # mysql decode
printDebug ("Comparing using mysql hash");
if (!try_use ("Crypt::MySQL qw(password password41)")) {Fatal ("Crypt::MySQL missing, cannot validate password"); return 0;}
my $encryptedPassword = password41($p);
$sth->finish();
return $state->{Password} eq $encryptedPassword;
}
else { # try bcrypt
if (!try_use ("Crypt::Eksblowfish::Bcrypt"))
{
Fatal ("Crypt::Eksblowfish::Bcrypt missing, cannot validate password");
return 0;
}
my $saved_pass = $state->{Password};
# perl bcrypt libs can't handle $2b$ or $2y$
$saved_pass =~ s/^\$2.\$/\$2a\$/;
my $new_hash = Crypt::Eksblowfish::Bcrypt::bcrypt($p, $saved_pass);
printDebug ("Comparing using bcrypt $new_hash to $saved_pass");
return $new_hash eq $saved_pass;
}
}
else
{
Expand Down

0 comments on commit c5a8311

Please sign in to comment.