Articoli con Tag ‘email’

reCAPTCHA: STOP allo SPAM

image C’è chi li odia e chi non ne può fare a meno! I Captcha (completely automated public Turing test to tell computers and humans apart), ovvero i sistemi di “controllo umano”, permettono nella maggior parte dei casi di eliminare molto della SPAM prodotto nella rete. reCAPTCHA è un servizio gratuito che permette di installare un proprio controllo Captcha sul proprio Web. Una volta registrati sul sito è possibile elencare i propri Web generando due chiavi (una pubblica e una privata: vedi La cifratura RSA) da usare in PHP, WordPress, e MediaWiki..

image

Sul sito è possibile trovare anche un servizio di protezione mail. In pratica viene rilasciato un codice da inserire nel proprio Web in modo tale da non visualizzare in chiaro un indirizzo email, tipo “i[...]@miodominio.com”. Cliccando verrà mostrato un Captcha da risolvere!

Vedi anche: 

Continua...

Classi Javascript e PHP per validare un’indirizzo di posta elettronica

Riprendendo il post Validare email in Javascript e PHP, ecco una simpatica classe Javascript in grado di verificare e controllare indirizzi di posta elettronica. Il suo uso è davvero semplice, anche se è un controllo lato client, quindi facilmente bypassabile; basta infatti disabilitare Javascript (propongo petizione contro questa possibilità ;) oramai tutti i browser permettono di eludere Javascript, e quindi tutti i controlli associato – a breve non funzionerà più nulla su Internet, vedi Ajax :o ).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
** @name              : ckmail.js
** @description       : Check email syntax
** @author            : =undo=
** @author-web        : http://www.undolog.com
** @author-email      : g.fazioli@undolog.com - g (dot) fazioli (at) undolog (dot) com
** @date              : 21/09/2006 21.24
** @ver               : 1.0
*/


var oCKMail = {
    __release: "1.0",
    __filter: /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i,
    __username: "",
    __domain: "",
    __ext: "",

    // TO DO
    getUsername: function(e) {
        if(this.__init(e)) return(this.__username);
        return(false);
    },

    // TO DO
    getDomain: function(e) {
        if(this.__init(e)) return(this.__domain);
        return(false);
    },

    // TO DO
    getExtension: function(e) {
        if(this.__init(e)) return(this.__ext);
        return(false);
    },

    // TO DO
    __init: function(e) {
        if( !this.__filter.test(e) ) return(false);
        var t = e.split("@");
        this.__username = t[0];
        this.__domain = t[1];
        t = this.__domain.split(".");
        this.__ext = t[1];
        return(true);
    },

    // TO DO
    // synopsis
    //    check(e,extlist,domainlist);
    // Esegue una serie di controlli standard su un indirizzo e-mail.
    //    extlist        - Si può passare un secondo parametro opzionale che corrisponde ad un array di estensioni che
    //                   sono ammesse o escluse (include/exclude extension) in base al primo valore dell'array, tutte le
    //                   altre saranno considerate errore.
    //                   Eg. [true,"it","com"] passano (include list)
    //                   Eg. [false,"it","com"] NON passano (exclude list)
    //                   Se -1 non viene preso in considerazione
    //    domainlist    - Si può passare un terzo parametro opzionale che corrisponde ad un array di domini che
    //                   sono ammessi o esclusi (include/exclude domain) in base al primo valore dell'array, tutte gli
    //                   altri saranno considerate errore.
    //                   Eg. [true,"alice.it","mac.com"] passano (include list)
    //                   Eg. [false,"alice.it","mac.com"] NON passano (exclude list)
    //                   Se -1 non viene preso in considerazione
    //
    check: function(e) {
        if( this.__init(e) ) {
            // check domainExt array check
            if( arguments.length > 1 ) {
                if( typeof( arguments[1] ) == "object" ) {
                    if( arguments[1][0] ) { // include list
                        for(var i=0; i < arguments[1].length; i++) {
                            if( this.__ext == arguments[1][i].toLowerCase() ) return(true);
                        }
                    } else { // exclude list
                        for(var i=0; i < arguments[1].length; i++) {
                            if( this.__ext == arguments[1][i].toLowerCase() ) return(false);
                        }
                        return(true);
                    }
                    return(false);
                }
            }
            // check domainName array check
            if( arguments.length > 2 ) {
                if( typeof( arguments[2] ) == "object" ) {
                    if( arguments[2][0] ) { // include list
                        for(var i=1; i < arguments[2].length; i++) {
                            if( this.__domain == arguments[2][i].toLowerCase() ) return(true);
                        }
                    } else { // exclude list

                        for(var i=1; i < arguments[2].length; i++) {
                            if( this.__domain == arguments[2][i].toLowerCase() ) return(false);
                        }
                        return(true);
                    }
                    return(false);
                }
            }
            return(true); // email correct
        }
        return(false); // error
    }
};

L’oggetto oCKMail mette a disposizione alcuni metodi per effettuare tutta una serie di controlli paralleli sull’indirizzo, come l’estensione, il dominio, ecc…

Per essere proprio sicuri se disponete di PHP potete aggiungere un’ulteriore ed efficace controllo prima di eseguire il comando mail(). Ecco la classe PHP utile a tale scopo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
** @name              : cckmail.php
** @description       : Check email syntax
** @author            : =undo=
** @author-web        : http://www.undolog.com
** @author-email      : g.fazioli@undolog.com - g (dot) fazioli (at) undolog (dot) com
** @date              : 21/09/2006 23.58
** @ver               : 1.0
**
** EXAMPLES
**
**    // Controlla un indirizzo ESCLUDENDO quelle e-mail con dominio "e-lementi.com" e "mac.com"
**
**    $oCKMail = new CCKMail();
**    $oCKMail->check($email, NULL, array(false,"e-lementi.com","mac.com") );
**
**    // Controlla un indirizzo INCLUDENDO quelle e-mail con dominio "e-lementi.com" e "mac.com"
**
**    $oCKMail = new CCKMail();
**    $oCKMail->check($email, NULL, array(true,"e-lementi.com","mac.com") );
**
**    // Controlla un indirizzo ESCLUDENDO quelle e-mail con estensione "net","it","org"
**
**    $oCKMail = new CCKMail();
**    $oCKMail->check($email, array(false,"net","it","org") );
**
** HISTORY / CHANGE LOG
**
*/


    if (!function_exists('checkdnsrr')) {
        function checkdnsrr($host, $type = '') {
            if(!empty($host)) {
                if($type == '') $type = "MX";
                @exec("nslookup -type=$type $host", $output);
                while(list($k, $line) = each($output)) {
                    if(eregi("^$host", $line)) {
                        return true;
                    }
                }
                return false;
            }
        }
    }
    //
    class CCKMail {
        var $__release = "1.1";
        var $status = false;
        var $username;
        var $domain;
        var $ext;
        //
        function CCKMail() {}
        //
        function _test($e) {
            $this->status = false;
            $p = '/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/';
            if( (preg_match($p, $e)) ) {
                $t               = explode("@",$e);
                $this->username  = strtolower( $t[0] );
                $this->domain    = strtolower( $t[1] );
                $t               = explode(".",$this->domain);
                $this->ext       = strtolower( $t[1] );
                //
                if(checkdnsrr($this->domain.'.', 'MX') )    $this->status = true;
                if(checkdnsrr($this->domain.'.', 'A') )     $this->status = true;
                if(checkdnsrr($this->domain.'.', 'CNAME') ) $this->status = true;
            }
        }
        //
        function check($m, $e=NULL,$d=NULL) {
            $this->_test($m);
            if( $this->status ) {
                // check domainExt array check
                if( !is_null($e) ) {
                    if( $e[0] ) { // include list
                        for($i=1; $i < sizeof($e); $i++) {
                            if( $this->ext == strtolower( $e[$i] ) ) return(true);
                        }
                    } else { // exclude list
                        for($i=1; $i < sizeof($e); $i++) {
                            if( $this->ext == strtolower( $e[$i] ) ) return(false);
                        }
                        return(true);
                    }
                    return(false);
                }
                // check domainName array check
                if( !is_null($d) ) {
                    if( $d[0] ) { // include list
                        for($i=1; $i < sizeof($d); $i++) {
                            if( $this->domain == strtolower( $d[$i] ) ) return(true);
                        }
                    } else { // exclude list
                        for($i=1; $i < sizeof($d); $i++) {
                            if( $this->domain == strtolower( $d[$i] ) ) return(false);
                        }
                        return(true);
                    }
                    return(false);
                }
                return(true);
            }
            return(false);
        }
    }
?>

La cosa ineteressante è la capacità di questa classe di connettersi ai server MX (vedi checkdnsrr() ) per verificare la presenza del dominio. Quindi oltre ad eseguire un controllo sintattico sull’indirizzo di posta elettronica viene eseguito un vero e proprio ping del dominio passato. Possiamo dire che questo metodo è sicuro all’80%…

Continua...

Validare email in Javascript e PHP

Per chi sviluppa moduli e FORM di contatti, esiste la necessità di verificare l’immisione di un indirizzo di posta elettronica. Oggi più che mai, con demoni pronti ad eseguire SPAM ovunque, è bene tutelarsi da “furbetti” pronti a sfruttare i moduli HTML per inviare mail illegali o eseguire hack per SPAM e quant’altro.

Continua...


Stop SOPA