Initial commit - chpassunivpm - Change univpm.it password
(HTM) hg clone https://bitbucket.org/iamleot/chpassunivpm
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) changeset cd5496f68907b3969e9e8f1b1191bc06f2f439c9
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Tue, 5 Jun 2018 22:06:57
Initial commit
Diffstat:
chpassunivpm.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 80 insertions(+), 0 deletions(-)
---
diff -r 000000000000 -r cd5496f68907 chpassunivpm.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/chpassunivpm.py Tue Jun 05 22:06:57 2018 +0200
@@ -0,0 +1,80 @@
+#!/usr/pkg/bin/python3.6
+
+#
+# Copyright (c) 2018 Leonardo Taccari
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+
+"""
+Change the password of univpm.it
+
+chpassunivpm is a simple script that permits to change the password
+used at univpm.it. It is similar to passwd(1) and asks for username,
+old password, new password and a confirmation of the new password.
+
+If the password is successfully changed an email is automatically sent to the
+user email address.
+"""
+
+
+import getpass
+from urllib import parse, request
+
+
+CHPASS_URL = 'https://apps.sia.univpm.it/chpass/registra.php'
+
+
+def chpass(username, old_password, new_password):
+ """Given an username, an old_password, new_password change the password.
+
+ If the password is changed successfully the user will recieve an email.
+ """
+ auth = parse.urlencode({
+ 'username': username,
+ 'old_password': old_password,
+ 'new_password_1': new_password,
+ 'new_password_2': new_password,
+ 'invio': 1,
+ })
+ auth = auth.encode('utf-8')
+
+ with request.urlopen(CHPASS_URL, data=auth) as f:
+ # XXX: Unfortunately it is needed to parse the HTML to understand if the
+ # XXX: password was changed or not. For the moment avoid to do that.
+ # XXX: (An email will be received if the password is changed
+ # XXX: successfully)
+ pass
+
+
+if __name__ == '__main__':
+ username = input('username: ')
+ old_password = getpass.getpass('old password: ')
+ new_password = getpass.getpass('new password: ')
+ if new_password != getpass.getpass('confirm new password: '):
+ print('New password and confirm new password are differents.')
+ exit(1)
+
+ chpass(username, old_password, new_password)