Software /
code /
prosody-modules
Comparison
mod_password_policy/mod_password_policy.lua @ 841:0649883de4d3
mod_password_policy: Initial commit.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Fri, 05 Oct 2012 05:49:22 +0500 |
child | 845:1c14edca74a4 |
comparison
equal
deleted
inserted
replaced
840:f568661c9d39 | 841:0649883de4d3 |
---|---|
1 -- Password policy enforcement for Prosody | |
2 -- | |
3 -- Copyright (C) 2012 Waqas Hussain | |
4 -- | |
5 -- | |
6 -- Configuration: | |
7 -- password_policy = { | |
8 -- length = 8; | |
9 -- } | |
10 | |
11 | |
12 local options = module:get_option("password_policy"); | |
13 | |
14 options = options or {}; | |
15 options.length = options.length or 8; | |
16 | |
17 local st = require "util.stanza"; | |
18 | |
19 function check_password(password) | |
20 return #password <= options.length; | |
21 end | |
22 | |
23 function handler(event) | |
24 local origin, stanza = event.origin, event.stanza; | |
25 | |
26 if stanza.attr.type == "set" then | |
27 local query = stanza.tags[1]; | |
28 | |
29 local passwords = {}; | |
30 | |
31 local dataform = query:get_child("x", "jabber:x:data"); | |
32 if dataform then | |
33 for _,tag in ipairs(dataform.tags) do | |
34 if tag.attr.var == "password" then | |
35 table.insert(passwords, tag:get_child_text("value")); | |
36 end | |
37 end | |
38 end | |
39 | |
40 table.insert(passwords, query:get_child_text("password")); | |
41 | |
42 for _,password in ipairs(passwords) do | |
43 if password and not check_password(password) then | |
44 origin.send(st.error_reply(stanza, "cancel", "not-acceptable", "Please use a longer password.")); | |
45 return true; | |
46 end | |
47 end | |
48 end | |
49 end | |
50 | |
51 module:hook("iq/self/jabber:iq:register:query", handler, 10); | |
52 module:hook("iq/host/jabber:iq:register:query", handler, 10); | |
53 module:hook("stanza/iq/jabber:iq:register:query", handler, 10); |