Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I want to make an application in c#, or in c++ or in what ever programming language even in script language as bash.

The application will ask for an answer, e.g. 1+1? and the password will be 2 If it is right then will log you in. I dont want to answer how i will write the application, just how to implement that action in linux.

How can i accomplish that in ubuntu. (10.04 or 12.04)

Thank you in advance, Best regards thio

share|improve this question

closed as too broad by muru, Eric Carvalho, David Foerster, mikewhatever, KasiyA Apr 1 at 4:53

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

Is this your homework? –  don.joey Aug 17 '13 at 18:13
If the homework requires from the app to get a 256-bit key and authenticate login through the network, yes could be –  Thio Aug 17 '13 at 18:17

1 Answer 1

up vote 3 down vote accepted

The code does not provide ways to authenticate through some network infrastructure using 256-bit key. It merely provides a plan to work on. The OP will have to build on the plan to complete his homework...

Bellow is a simple Python code performing a small puzzle game representing most of the requested logic. See the comments in code for online resources about Python and some hints about each line of code.


Added code to start X server as requested by the OP. The code uses the subprocess module. I have not tested the start_x function but it should be close to the requested functionality.

#!/usr/bin/env python
"""A mini puzzle game using Python 2.7.5 programming language
and the random module from the standard library.
Python 2.7.5 documentation
Online Python books
import random
#import the subprocess module
import subprocess

def do_ask_random_sum_result():
    """Asks for the result of the addition of two random integers"""

    # get the two random integers from
    # a set of integers {0, 1, 2, 3, 4, 5}
    first_random = random.randint(0,5)
    second_random = random.randint(0,5)

    # perform addition and store the
    # result to random_sum
    random_sum = first_random + second_random
    # print the two random numbers to output
    # asking the user for the result of their
    # addition
    result = input("What is the sum of {0} + {1}? ".format(
        first_random, second_random))
    # check if the user input matches
    # the result
    if random_sum == result:
        # instead of printing something
        # perform the log in to whatever you
        # want the user to log in
        print("That is correct, the result is: {0}".format(random_sum))
        print("Performing log in procedures...")
    # Cannot perform the log in since
    # the user provided a wrong answer...
        print ("Wrong answer!")

def do_login():
    """Performs the login"""

    # perform various login actions
    # and finally try to start X server
        # call the start_x function
    except Exception as e:
        print ("Could not start X server")
        print ("Error details:\n{err}".format(err=e.message))

def start_x():
    """Starts the x server using the subprocess module
        NOT TESTED but it must be something close to this

    #declare proc as new process to launch
    proc = subprocess.Popen("startx", shell=True, stdout=subprocess.PIPE)
    #assign the output of proc to output variable this is optional
    #for just to check what x has to say
    output =
    #print the results
    print (output)

def main():
    """Application's main entry"""


if __name__ == '__main__':
share|improve this answer
Thank you very much! –  Thio Aug 21 '13 at 20:49
This snippet is very nice and thank y very much. Can someone provide me some solution for do_login() function. How can login a user and start startx server through python? –  Thio Aug 21 '13 at 20:54
@Thio i have added a start_x function to start the X server but it is not tested. As for the login i don't know what exactly are the requirements when you say login but this is something you should analyze as a part of your homework. –  Stef K Aug 21 '13 at 21:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.