chpassunivpm.py - chpassunivpm - Change univpm.it password
 (HTM) hg clone https://bitbucket.org/iamleot/chpassunivpm
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
       chpassunivpm.py
       ---
            1 #!/usr/pkg/bin/python3.7
            2 
            3 #
            4 # Copyright (c) 2018-2019 Leonardo Taccari
            5 # All rights reserved.
            6 # 
            7 # Redistribution and use in source and binary forms, with or without
            8 # modification, are permitted provided that the following conditions
            9 # are met:
           10 # 
           11 # 1. Redistributions of source code must retain the above copyright
           12 #    notice, this list of conditions and the following disclaimer.
           13 # 2. Redistributions in binary form must reproduce the above copyright
           14 #    notice, this list of conditions and the following disclaimer in the
           15 #    documentation and/or other materials provided with the distribution.
           16 # 
           17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
           18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
           19 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
           20 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
           21 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
           22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
           23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
           24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
           25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
           26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
           27 # POSSIBILITY OF SUCH DAMAGE.
           28 #
           29 
           30 
           31 """
           32 Change the password of univpm.it
           33 
           34 chpassunivpm is a simple script that permits to change the password
           35 used at univpm.it. It is similar to passwd(1) and asks for username,
           36 old password, new password and a confirmation of the new password.
           37 
           38 If the password is successfully changed an email is automatically sent to the
           39 user email address.
           40 """
           41 
           42 
           43 import getpass
           44 from urllib import parse, request
           45 
           46 
           47 CHPASS_URL = 'https://phproc.univpm.it/apps.sia/chpass/registra.php'
           48 
           49 
           50 def chpass(username, old_password, new_password):
           51     """Given an username, an old_password, new_password change the password.
           52 
           53     If the password is changed successfully the user will recieve an email.
           54     """
           55     auth = parse.urlencode({
           56         'username': username,
           57         'old_password': old_password,
           58         'new_password_1': new_password,
           59         'new_password_2': new_password,
           60         'invio': 1,
           61     })
           62     auth = auth.encode('utf-8')
           63 
           64     with request.urlopen(CHPASS_URL, data=auth) as f:
           65         # XXX: Unfortunately it is needed to parse the HTML to understand if the
           66         # XXX: password was changed or not. For simplicity avoid to do that.
           67         # XXX: (An email will be received if the password is changed
           68         # XXX: successfully)
           69         pass
           70 
           71 
           72 if __name__ == '__main__':
           73     username = input('username: ')
           74     old_password = getpass.getpass('old password: ')
           75     new_password = getpass.getpass('new password: ')
           76     if new_password != getpass.getpass('confirm new password: '):
           77         print('New password and confirm new password are differents.')
           78         exit(1)
           79 
           80     chpass(username, old_password, new_password)