~ubuntu-branches/ubuntu/trusty/ejabberd/trusty-proposed

« back to all changes in this revision

Viewing changes to src/ejabberd_auth.erl

  • Committer: Bazaar Package Importer
  • Author(s): Konstantin Khomoutov
  • Date: 2010-12-14 17:45:08 UTC
  • mfrom: (1.1.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20101214174508-6vgu3uw3ki6x8vj2
Tags: 2.1.6-1
* New upstream release.
* Remove obsolete patches.
* Update mod_admin_extra to revision 1106.
* Conflict with ejabberd-mod-shared-roster-ldap which is now included.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
         is_user_exists_in_other_modules/3,
50
50
         remove_user/2,
51
51
         remove_user/3,
52
 
         plain_password_required/1
 
52
         plain_password_required/1,
 
53
         entropy/1
53
54
        ]).
54
55
 
55
56
-export([auth_modules/1]).
318
319
    end,
319
320
    R.
320
321
 
 
322
%% @spec (IOList) -> non_negative_float()
 
323
%% @doc Calculate informational entropy.
 
324
entropy(IOList) ->
 
325
    case binary_to_list(iolist_to_binary(IOList)) of
 
326
        "" ->
 
327
            0.0;
 
328
        S ->
 
329
            Set = lists:foldl(
 
330
                    fun(C, [Digit, Printable, LowLetter, HiLetter, Other]) ->
 
331
                            if C >= $a, C =< $z ->
 
332
                                    [Digit, Printable, 26, HiLetter, Other];
 
333
                               C >= $0, C =< $9 ->
 
334
                                    [9, Printable, LowLetter, HiLetter, Other];
 
335
                               C >= $A, C =< $Z ->
 
336
                                    [Digit, Printable, LowLetter, 26, Other];
 
337
                               C >= 16#21, C =< 16#7e ->
 
338
                                    [Digit, 33, LowLetter, HiLetter, Other];
 
339
                               true ->
 
340
                                    [Digit, Printable, LowLetter, HiLetter, 128]
 
341
                            end
 
342
                    end, [0, 0, 0, 0, 0], S),
 
343
            length(S) * math:log(lists:sum(Set))/math:log(2)
 
344
    end.
321
345
 
322
346
%%%----------------------------------------------------------------------
323
347
%%% Internal functions