Wednesday, 15 February 2017

Twitter Application-Only Authentication in Python

Twitter provides a number of REST API endpoints. All endpoints require requests to be authenticated. Authentication can be done with any of the two:

Application-only authentication is useful in cases where the user context is not available or is simply not required. Not all endpoints support it, since many of them would need user grant before a request is made on a user's behalf. Such endpoints could be for creating tweets for a user, deleting them, et cetera. A small subset of endpoints does not require user context. Search Tweets is one such endpoint. In the rest of the post I'll create a client that implements application-only authentication flow in Python.

You're going to need the Requests package. You must also register a Twitter app at https://apps.twitter.com/ to obtain Consumer Key and Consumer Secret for the application.

Encoding Consumer Key and Secret

Twitter requires the consumer key and secret to be encoded before requesting the Bearer token. Bearer token credentials can be obtained easily:

  • URL encode both Consumer Key and Secret
  • Concatenate them with a semicolon in between
  • Encode the result in Base64

from urllib.parse import quote_plus
from base64 import b64encode


def get_bearer_credentials(consumer_key, consumer_secret):
    encoded_ck = quote_plus(consumer_key)
    encoded_cs = quote_plus(consumer_secret)

    credentials = '{}:{}'.format(encoded_ck, encoded_cs)

    b64credentials = b64encode(credentials.encode('ascii'))
    return b64credentials.decode('ascii')

Requesting the Bearer token

Bearer token can be obtained by making a POST request to https://api.twitter.com/oauth2/token with the Authorization header containing the Bearer credentials. Twitter implements Client Credentials Grant of OAuth2 as defined in RFC-6749. As per the RFC, the server must respond with an Access token for a valid client request (having valid credentials). The Access token can be of certain types, Bearer is one of them and is what Twitter uses. A valid request for Bearer token must have:

  • Authorization header set to Basic {{ credentials }}
  • Content-Type header set to application/x-www-form-urlencoded;charset=UTF-8
  • grant_type=client_credentials as request body

import requests

OAUTH2_TOKEN_URL = 'https://api.twitter.com/oauth2/token'


def get_access_token(bearer_credentials):
    headers = {
        'Authorization': 'Basic {}'.format(bearer_credentials),
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    }
    data = 'grant_type=client_credentials'

    response = requests.post(OAUTH2_TOKEN_URL, data=data, headers=headers)

    if response.status_code != requests.codes.ok:
        raise Exception('Invalid request or invalid credentials')

    response_body = response.json()
    if response_body.get('token_type', '') == 'bearer':
        access_token = response_body.get('access_token')
        return access_token
    else:
        raise Exception(('Invalid token type of returned access token. Token type')
                       ('is not bearer.'))

Making an authenticated request

An authenticated request can be constructed by setting the Authorization header to Bearer {{ access_token }}. The following is an example request to fetch popular tweets containing the hashtag twitter:

import requests

SEARCH_TWEETS_URL = 'https://api.twitter.com/1.1/search/tweets.json'

# `access_token` obtained in the above step
headers = {'Authorization': 'Bearer {}'.format(access_token)}
payload = {'q': '#twitter', 'count': 10, 'result_type': 'popular'}


response = requests.get(SEARCH_TWEETS_URL, params=payload, headers=headers)

if response.status_code != requests.codes.ok:
    raise Exception('Invalid request')

# Twitter Statuses (tweets)
status_list = response.json().get('statuses', [])

Invalidating Bearer token

A Bearer token can be invalidated by making a POST request to https://api.twitter.com/oauth2/invalidate_token with the Authorization header and body correctly set.

import requests

INVALIDATE_URL = 'https://api.twitter.com/oauth2/invalidate_token'


def invalidate_token(bearer_credentials, access_token):
    headers = {
        'Authorization': 'Basic {}'.format(bearer_credentials)}
        'Content-Type': 'application/x-www-form-urlencoded'
    }
    data = 'access_token={}'.format(access_token)

    response = requests.post(INVALIDATE_URL, data=data, headers=headers)

    if response.status_code != requests.codes.ok:
        raise Exception('An error occurred. Access token was not invalidated.')

    print('Access token was invalidated.')

Handling common errors

Twitter's documentation describes some common errors that might occur while getting or invalidating a Bearer token, or while performing some action through an authenticated request. The code below is a simple check for these errors:

# a `response` after a request
if response.status_code != requests.codes.ok:
    errors = response.json()
    for error in errors:
        print('Code: {}, Message: {}'.format(error.code, error.message))

---

I've created a simple application using the above APIs: shivamMg/kayak


Sunday, 29 January 2017

SBI Global International "Visa" Debit Cards now work with PayPal

TL;DR SBI Global International Visa (Not MasterCard) Debit Cards now work with PayPal.

Sun must have risen in the west or something, SBI Global Visa debit cards can now be linked to your PayPal account. There doesn't seem to be any official announcement yet, but I tried making a payment through PayPal today and it worked (your bhai finally bought shivammamgain.com domain). You can apply for the card at any SBI branches (or use your Online SBI account if you have one). Make sure you ask for a Global International "Visa" debit card. MasterCard still doesn't work. I tried both.

The Bank will ask you to fill in an application for the card. Also if you don't have an Online SBI account, do yourself a favor and apply for that too. It'll make the entire process less PITA. After you receive the card, you'll need to switch on some services for the card: ATM/POS/E-Commerce channels (ATM/POS/ECOM) and Domestic/International Usage (DOM/INTL). Details on how to do it will be on a pamphlet in the same mail. POS, ECOM and INTL seem to be the only ones needed for use in International payments (I applied for all by the way).

When I tried linking the MasterCard at PayPal, PayPal would debit my account for some amount (to confirm the card). But then the amount would be credited back and PayPal wouldn't confirm it. With Visa, the amount will be debited and PayPal will ask for a 4 digit code that you can get from the transaction details. Again, Online SBI account will be much helpful. It displays the last ten transactions for your account. You can get the 4 digit code from there.

I've got four SBI debit cards now. Classic (the one I already had), Classic (there must've been some mistake when I ordered a MasterCard for the first time, I received this instead), MasterCard (now useless since it doesn't work), Visa (finally).


Sunday, 2 October 2016

GSoC'16 overview

summerofcode.withgoogle.com/archive/2016/projects/4901518415233024

It's been an entire month after GSoC'16 ended. I provided a GitHub link of my contributions as the final submission link. I didn't write a blog post covering my contributions. This post covers my work done during the GSoC period. It contains links to some of my posts at blog.fossasia.org. I mainly worked with the APIs and the Permissions system.

# APIs

Swagger

blog.fossasia.org/swagger

A part of the project was creating Swagger specification for our APIs. Our application was written in Flask and APIs were supposed to be written in Flask-RESTplus. The best part about RESTplus was its integration with Swagger. You could document your API Views and it would generate the specification. RESTplus provides Pluggable Resource views that can be extended for GET, POST, PUT and DELETE request handlers. It also provides decorators for documenting other details about the Resource, like response models and possible error responses.

API Error Response Models

blog.fossasia.org/errors-and-error-handlers-for-rest-api

During the initial GSoC period we spent some time on discussing how the APIs should be structured. Here's an Issue#336 of the same. Later that period I defined error response models for the APIs. Implementing them was quite easy with RESTplus.

ETag based caching for GET APIs

blog.fossasia.org/etag-based-caching-for-get-apis

This post includes implementing ETag based caching and how clients can cache responses based on the ETags.


# Permissions System

Roles and Permissions

blog.fossasia.org/organizer-server-permissions-system

Apart from the APIs I also worked a lot on the Servers Permission System. It included defining System Roles and Event Roles that could be assigned to users. The blog post covers these roles and their permissions in detail.

Shell Hacks

blog.fossasia.org/shell-hacks

A small post about some hacks I took up to increase productivity when using shell.

Permission Decorators for APIs

blog.fossasia.org/permission-decorators

If you have defined the APIs nicely, then implementing permissions becomes really easy. As I told before, Flask RESTplus provides a Resource class that has get(), post(), put(), delete() methods to deal with the different request methods. We had DAOs (Data Access Objects) defined for our database models that had create(), update() like methods defined for them. Every Resource was bound to a DAO, and fulfilling an HTTP request meant using a DAO method according to the request method.

To implement permissions, I created decorators over the DAO methods create(), read(), etc. The post is about the same.


# Real-Time user notifications

Setting up Nginx and Gunicorn for using Sockets

blog.fossasia.org/setting-up-nginx-gunicorn-and-flask-socketio

This post is about setting up environment for creating Real-Time user notifications.

Flask-SocketIO

blog.fossasia.org/flask-socketio-notifications

Implementing User notifications through WebSockets using Flask-SocketIO.


# Others

Apart from these I also worked on Tickets, mainly UI and form handling.

Multiple Tickets: UI

blog.fossasia.org/multiple-tickets-user-interface

Multiple Tickets: Backend

blog.fossasia.org/multiple-tickets-back-end

AJAX image upload

blog.fossasia.org/ajax-image-upload-at-wizard

User Notifications: DB model

blog.fossasia.org/user-notifications

Monday, 16 May 2016

GSOC 2016

I came to know about Google Summer Of Code last year. For the uninitiated, it's an annual program organized by Google to promote Open Source. Organizations that want to be a part of GSOC send proposal requests to Google, who selects potential organizations and puts out a list. Students apply by sending proposals on Open Source project ideas to these accepted organizations. An idea can either come from the student himself or by selecting one from the ideas list provided by the organization. There is a limit on the number of proposals by a student.

I wasn't able to apply last year, more or less because of my limited knowledge about Open Source. I had just started to learn git then and worked only on small web based projects. Over the year I learnt a lot. Before OSS development I had more interest in competitive programming. Couldn't continue it, after a while it really becomes monotonous, especially if you don't move over from solving basic mathematical problems to problems that require knowledge about specific concepts, like dynamic programming, graph based algorithms, etc. Knowing these concepts requires going through a lot of theory, which wasn't exactly what I like. I had more interest in web development, and had worked with the XAMPP stack. With a little knowledge about Git and GitHub I started off with Open Source.

By the end of the year, I had taken up Python as my go-to programming language and even taught myself Django. The GSOC program and timeline were announced in October, but I didn't select what organizations to work with until after December. Even then I started contributing code only after January end. By February, I had made up my mind to go with two organizations. One was CloudCV and the other was FOSSASIA.

CloudCV mainly deals with providing cloud as a service for Computer Vision. It makes it easier for researchers to, for example run their computer vision algorithm on the CloudCV platform so they don't have to setup infrastructure. They do this by providing APIs for developers to work with. So it was more about working with image processing softwares than web development. Their website was on Django. FOSSASIA on the other hand, dealt with organizing technology summits and talks promoting FOSS. It is the largest Open Source organization in Asia. Projects at FOSSASIA were mostly web based. I started contributing to both of them. By the start of March I was pretty sure I was going with FOSSASIA, being a web developer I was able to contribute more.

FOSSASIA had multiple projects under it. The one that interested me the most was the Open Event Organizer Server. FOSSASIA organizes many events each year. The server provides an interface for the organizers to enter data about the sessions and speakers for the event, and provides API endpoints to read that data. These APIs are consumed by the Open Event Web App and Android Client to display data to the users. The server's written in Python and runs on Flask. As the student application deadline came closer I started focusing more on the organizer server.

With the deadline a week away, I had prepared two proposal ideas. One was a web app with focus on Event Sessions. Here's an overview, copied straight off from my proposal:

The idea is to direct more focus towards Open Event Sessions. The current applications (both OE web app and OE android app) that handle display of Event data lack interactivity and options to share Sessions. Users cannot review sessions, sessions listed are not shareable, there is no mechanism to rate them on the basis of their performance. Moreover, sending proposals for sessions requires users to log in to the administrator site (OE Organizer Server) and then send proposals. My proposal is to create a Flask application alongside the Organization Server that lets users sign in with Social Media platforms. This will enable them to send Session Proposals and write Reviews. At the end I’ll create API endpoints to create/update/delete Session Proposals and Reviews. These APIs can then be used to provide the same functionality to Android app.

My second proposal was to improve the current server app and create API endpoints to write data to the server. This included providing bug fixes and tests for the existing server. Creating write APIs meant making the server to accept POST/PUT/DELETE requests. I had more expectations from the first proposal. I had put up a lot of time in creating that proposal, describing how the entire app would work. The second one got selected though (Not that I'm complaining, just that I saw more potential in the first one.).

The work has already begun. I've started providing bug fixes and improvements to the server. The server would be going through major changes this summer.

I'm happy I didn't select a front-end project to go with. I had worked on a lot of front-end projects the previous year and wanted a switch to back-end.


Tuesday, 10 May 2016

MALVO for Colosseum'16

This year has been pretty busy for now. I had been wanting to create a new platform for Lord of the Code, a college programming competition. It's held each year on Colosseum, our technical fest. The competition includes two rounds. Round one consists of MCQ challenges where each team is served with 50 questions on the language of their choice (C or Java). The finalists of the first round enter second round to solve programming challenges. There are ten questions to be solved in 2 hours of time. The job to create such a platform doesn't really look big until you begin and somehow enter the mid phase.

I had to build the entire site from scratch. For my platform I had to build both the front-end and back-end. I decided to go with Semantic-UI on front and with Django at back-end. Also I had a different idea for the implementation.

The MCQs round being the first round always had a lot of participants. It consisted of 50 MCQs that had to be solved within one hour. The MCQs on their site were served one for every request. So if you solved MCQ one (/mcq/1) you would then be directed to MCQ two (/mcq/2), and this goes on for other 48 MCQs. The server had to bear a lot of load. My idea was to send the MCQs at the client all at once. The team would then solve all the problems and upload all the answers once. Basically a single page application. The second round had fewer teams than the first one, so challenges were served at requests (/challege/<no>), no new stuff there. Plus it would have been more complex for an SPA because of the varying number of input test cases and therefore varying form fields.

I wanted the site to be neat. Semantic-UI looked great when I implemented it in templates. I also put up markdown support for question text and syntax highlighting for code (Yup! previous site didn't have syntax highlighting for code). MD support was provided by Showdownjs and highlighting by HighlightJS. Both are awesome libraries.

On a side note, I did not know you could download a custom package for HighlightJS depending on your language choices. Since the only two languages we were concerned with were C and Java, I didn't have to download the entire default HighlightJS library. I could download a custom package that supports only C and Java. Noice!

This project was pretty big, considering I had to create all models/views/templates from scratch. It was the biggest project by me in terms of lines of code (>6000), and I was happy that I completed it before the event date. Unfortunately, the organizers didn't use it for the MCQ round and decided to go with the older platform.

The Older software has been in use for more than three years.

They let me setup the site for the second round though. It worked great and didn't have any issues. Although watching it work as expected in the MCQ round would have been great. Anyways, I'll be setting up the site for the next competition, Code Connoisseur'16, which will be in August I think. I might even join the society and be a part of the organizing team. Why I didn't join it before? that would start another story.

Here's the source for the project: malvo. I'll be creating a Docker image so deployment becomes easier. But that's for some other day... probably.

Some edits were made to the post...


Thursday, 14 January 2016

:VimKnight


Ah, you think vimL is your ally?
You merely adopted vim. I was born in it, molded by it.
Didn't see fancy IDE until I was already a ninja, by then
it was nothing to me but INSERT mode.

Friday, 18 September 2015

Typewriter

Words that can be typed by using exactly one set of keys, i.e.
Either
Q W E R T Y U I O P
or
A S D F G H J K L
or
Z X C V B N M

import re

if __name__ == '__main__':
    regex = re.compile(r'^([qwertyuiop]*|[asdfghjkl]*|[zxcvbnm]*)$')
    with open('words.txt', 'r') as fptr:
        for word in fptr:
            if regex.match(word):
                meat = regex.match(word).group(1)
                # Print words with length greater than 7:
                if len(meat) > 7:
                    print('%s (%d)' % (meat, len(meat)))
etiquette (9)
perpetuity (10)
pirouette (9)
potpourri (9)
preterite (9)
prettier (8)
priority (8)
property (8)
proprietor (10)
propriety (9)
prototype (9)
puppeteer (9)
puppetry (8)
repertoire (10)
repertory (9)
reporter (8)
territory (9)
torturer (8)
tripwire (8)
typewriter (10)

Typewriter is one of the largest in the result set, but not the only one.


Saturday, 1 August 2015

Nth Term

InternetIsBeautiful

A couple of days back I stumbled upon this website: nth-test.com. Nth Test is an nth-child and nth-of-type tester. It requires you to input an nth term of a sequence and it displays the sequence formed corresponding to that nth term. What it basically does is that it calculates the Arithmetic Progression (A.P.) for that nth term. So for example if we input 2n-1, it will output the progression: 1, 3, 5, 7 ... on a tabular block in an interactive way. It makes calculating the nth child easier.

So I came out with Nth Term that does the exact opposite of the above explained concept. It takes the sequence (Arithmetic Progression) as input and displays the nth term for it. It also extends the input sequence and highlights the numbers on a table.

So suppose you need the nth term for the following sequence: 5, 9, 13 ...
All you need to do is type the numbers in the input form separated by commas and you will get the nth term and the extended sequence for the input.

I have defined n as a Natural Number, i.e. n ∈ N. So n can only take values from the set: { 1, 2, 3, 4, ... }. You may enter values of n and check if the output series is correct in the table.

For n = 1, 4n+1 = 5
For n = 2, 4n+1 = 9
For n = 3, 4n+1 = 13
For n = 4, 4n+1 = 17

... and so on.

You may have noticed a smiley to the left of the input form. A smile : ) means a hit, i.e. the nth term has been found. A sad face : ( means the series is not an A.P. and when it is waiting for a proper input by you, it would display an "indifferent" smiley : |

Saturday, 28 February 2015

Skepticism


Almost every Classmate notebook has a page at the end with some interesting facts on it. In my notebook, one of the facts went like this:
Skepticism is the longest word that can be typed with alternate hands.
A list of all valid English words is available in Linux systems. You can get them too, /usr/share/dict/words. So I decided to check the fact and retrieve the largest word that can be typed with alternate hands.
I wrote a Python script to do it.

Flip = lambda X: 0 if X == 1 else 1 
Alibaba = lambda X: 0 if X in left_hand else 1

babloo = str()                # Required string    
babloo_len = 0        

left_hand = 'ASDFGQWERTZXCV'  # Alphabets assigned to Left hand
right_hand = 'LKJHPOIUYMNB'   # Alphabets assigned to Right hand

filename = 'words.txt'        # File with all valid words, 
                              # one on each line  

if __name__ == '__main__':    
    my_file = open(filename, 'r') 
    
    for line in my_file:
        word = line.rstrip().upper()
    
        Clock = Alibaba(word[0])

        sync = True
        for alphabet in word:
            if Alibaba(alphabet) != Clock:  
                sync = False                
                break
            Clock = Flip(Clock)

        if sync:
            print(word, end=',')
            if len(word) > babloo_len:
                babloo = word
                babloo_len = len(word)

    my_file.close()

    print("\n")
    print("Largest word is %s with a length of %d alphabets" 
           % (babloo, babloo_len))

# No offence meant, Babloo

This extracts all the required words and displays the largest of them. They came out to be AUTHENTICITY and ABSORPTIVITY, which have a character length of 12. There are others with a character length of 11. These include DISBANDMENT, ENCHANTMENT, ENTITLEMENT, PROFICIENCY and SHANTYTOWNS. You can modify the script to extract them too.

EDIT: A code golf solution

Written keeping in mind to traverse a word just once.

FILENAME = 'words.txt'
required_words = []

for w in map(lambda s: s.upper(), open(FILENAME, 'r').read().splitlines()):
    prev = None
    for now in map(lambda l: 1 if l in 'ASDFGQWERTZXCV' else 0, w):
        if now == prev: break
        prev = now
    else:
        required_words.append(w)

print(max(required_words, key=len))

Tuesday, 12 August 2014

MTS MBlaze ubuntu setup


Bought an MTS MBlaze and set it up on Ubuntu Precise (12.04). I tried the autorun.sh script provided with the USB, in its flash storage. They described this in a How-to-install.txt. Script didn't work.

So, I tried using it through the detected CDMA connection. Enabled networking, manually edited the connections and set username:internet@internet.mtsindia.in and password : MTS. This didn't work either. The MTS network was detected but it could not be connected to. DuckDuckGo'ed the problem and found a soution.

Here, I followed exactly these steps:

  • Issue at terminal:
    sudo apt-get install wvdial
  • Issue at terminal:
    sudo apt-get install usb-modeswitch usb-modeswitch-data
  • Edit /etc/wvdial.conf and add this to it:
    [Dialer mts]
    Stupid Mode = 1
    Inherits = Modem0
    Password = mts
    Username = internet@internet.mtsindia.in
    Phone = #777
    [Modem0]
    Init1 = ATZ
    SetVolume = 0
    Modem = /dev/ttyUSB0
    Baud = 115200
    FlowControl = Hardware (CRTSCTS)
    Dial Command = ATDT
    
  • Save the file (make sure you edit it as root).
  • Issue@Terminal:
    sudo wvdial mts

wvdial then starts the connection and you can start browsing.

wvDial is a point-to-point protocol dialer [P2P Protocol]. It is used to establish a direct connection between nodes.
About usb-modeswitch, it is needed in Linux. The USB modem comes with on-board drivers for windows, and when plugged in, the drivers are installed (normal for flash storage devices). If the drivers are already installed the USB modem comes up.
In Linux, this usb-modeswitch tool is needed to switch flash-storage to usbserial.

Wednesday, 6 August 2014

Room Allocation : Results

Allotted Rooms


5Deepankar ChaudharyNachiketa PrakashVACANT
6Aman goswamiBhupesh NegiPanaj singh
7Sharukh KhanSalman KhanAamir Khan
8Aseem RainaNavodit MehtaVACANT
9Rajvardhan KaviSiddharth NegiVACANT
10bharat kumar satiVACANTVACANT
11PARANTAP JOSHIANIRUDH TRIPATHIHarshit Joshi
12Jiteen BhandariVACANTVACANT
13VACANTVACANTVACANT
14VACANTVACANTVACANT
15VACANTVACANTVACANT
16VACANTVACANTVACANT
17atul prakashkamlesh pratap pandeyVACANT
18Shivam Mamgainnaveen chauhanvivek kumar
19VACANTVACANTVACANT
20VACANTVACANTVACANT
21rohit joshiVACANTVACANT
22Anurag Dudejauday pratapVACANT
23VACANTVACANTVACANT
24VACANTVACANTVACANT
25VACANTVACANTVACANT
26TUSHAR JOSHIBIRENDRA VIKRAM SINGHVACANT
27VACANTVACANTVACANT
28VACANTVACANTVACANT
29Trinayan BhattVACANTVACANT
30VACANTVACANTVACANT
31VACANTVACANTVACANT
32VACANTVACANTVACANT
33Rohan ZutshiKartikey MamgainAyush Bhandari
34VACANTVACANTVACANT
35VACANTVACANTVACANT
36VACANTVACANTVACANT
37VACANTVACANTVACANT
38VACANTVACANTVACANT
39VACANTVACANTVACANT
40VACANTVACANTVACANT
41VACANTVACANTVACANT
42VACANTVACANTVACANT
43VACANTVACANTVACANT
44VACANTVACANTVACANT
45VACANTVACANTVACANT
46VACANTVACANTVACANT
47VACANTVACANTVACANT
48VACANTVACANTVACANT
49VACANTVACANTVACANT
50VACANTVACANTVACANT
51Somesh LohaniHitesh LohaniAnmol Ratna Pant
52SANCHIT GOELHARSH BANSALABHISHEK SOI
53Mayank SaxenaROHIT RAKSHITSHUBHAM CHAUBEY
54YASH BHANDARIVACANTVACANT
55Ayush SharmaSuyash PandeyGAURAV CHAND
56Prakamya JoshiUmang KumarVACANT
57Aman pandeysiddarth bistAbhishek Chandra
58Angelina jolieMegan FoxSATYAVRAT SARAN
59AJAY RAWATVACANTVACANT
60SHANTANU VERMAAJAY JOSHIVACANT
61VIJAY ARORAVACANTVACANT
62VACANTVACANTVACANT
63VACANTVACANTVACANT
64VACANTVACANTVACANT
65Aditya KumarSaurabh ThakurVACANT
66VACANTVACANTVACANT
67VACANTVACANTVACANT
68VACANTVACANTVACANT
69VACANTVACANTVACANT
70VACANTVACANTVACANT
71VACANTVACANTVACANT
72VACANTVACANTVACANT
73VACANTVACANTVACANT
74VACANTVACANTVACANT
75VACANTVACANTVACANT
76VACANTVACANTVACANT
77VACANTVACANTVACANT
78VACANTVACANTVACANT
79VACANTVACANTVACANT
80VACANTVACANTVACANT
81VACANTVACANTVACANT
82VACANTVACANTVACANT
83VACANTVACANTVACANT
84VACANTVACANTVACANT
85VACANTVACANTVACANT
86VACANTVACANTVACANT
87VACANTVACANTVACANT
88VACANTVACANTVACANT
89VACANTVACANTVACANT
90VACANTVACANTVACANT
91VACANTVACANTVACANT
92VACANTVACANTVACANT
93VACANTVACANTVACANT
94VACANTVACANTVACANT
95VACANTVACANTVACANT
96VACANTVACANTVACANT
97VACANTVACANTVACANT
98VACANTVACANTVACANT
99VACANTVACANTVACANT
N-1Karan kanwalRajendra Singh MerVACANT
N-2vaibhav bijolaVACANTVACANT
N-3PrateekVACANTVACANT
N-4VACANTVACANTVACANT
N-5VACANTVACANTVACANT
N-6VACANTVACANTVACANT
N-7VACANTVACANTVACANT
N-8Prince KumarHimanshu SindhwaniVACANT
N-9VACANTVACANTVACANT
N-10Akhilesh YadavVijay KumarVACANT
N-11Shankar BatraAkash GangwarKishore Kumar
N-12Ankush kumar singhalshivi bansalVACANT

Tuesday, 5 August 2014

Tagore Hostel : Room Allocation started

Tagore Room Allocation

The 81 days long Summer Vacation is now coming to an end. 21st August, 2014 is the Registration Day. Happy, that boring holidays are getting over. Angry, that our Batch has been alloted the same Hostel, Tagore (rumours or truth, vo to abhi pata nahi). With the Fine(st) facilities and the Best Mess, Tagore Hostel is one of the worst places to reside. So, what could could be more intimidating than the fear to spend another year in Tagore...
I guess, Starting an Online Room Allocation Website and ditching the rumours aside would be a cool prank.

Developing the Site

I needed something for students to trust the site, 'Office of Registrar, Pantnagar' anyone??...To make students believe, I had to imitate the front-end very closely. Saving the entire webpage through chrome isn't difficult.
Here's the difficult part. Developing the back-end with PHP and MySQL. Actually, it wasn't tough either. What annoyed me the most, was to think of an idea to make sure that every guy allocates a room only once, given I had no way to check if he has already done that (there was no way for me to identify unique visitors). The Solution was an obfuscated use of Cookies and Databases. I won't go into detail, but the code had loopholes. And I could only hide them by making the users trust the site, or else the plan fails.

Plan

is simple. Gain user trust at the first page, request their IDs and Passwords, albeit passwords had no importance. Even if you entered an invalid one, there was no way for me to check. The IDs were required to make sure students allocate room only once. Besides this, there were other loopholes too. One was inadvertent. The user could use the back button of browser and allocate rooms as many times he likes. Fortunately, I figured it out when Neeraj started doing it, and had that resolved.

As I told, there was no way to check the entered passwords, some students figured that out, and the site was soon declared "FARZI". But, still it wasn't clear to most. It was only after Megan Fox and Angelina Jolie Allocated a room for themselves (with Satya, :D), people declared it fake.
I didn't use student IDs to fill the Allocated_Rooms table, Instead I used their names provided (when requested) at Room-selection-page. This idea makes the site more engaging,,,whos-with-whom?? kind of thing.

Result

Awesome, yeah! Pretty Awesome. The site was online for only 4.5 hours (after that it got disabled by the host becoz of the CPU usage limit.


TheQuestion

If we entered the correct passwords at the site, Were they saved in Db?
The answer is : ABSOLUUUUUTELY
But I don't have them anymore, I deleted the table from the Database.You may check (or even change) your passwords if you are skeptical. Besides, the table had a lot invalid IDs (many entered by myself) and invalid passwords too. I won't go all the way through checking what ones are correct.

Sab Simtate hue aur Maff-iya mangte hue

Jis kisi ko, meri taraf se thes pahuchi ho....usse..me...maaffi
.
.
.
.
.
.
.
.
.
.
.
.
bhala kyu maangu?? :P .
I mean I helped you change "SYST", something you don't consider important.