I have installed Nulkta through pip install commands, but when I run it and try to package it, this is what it give me.
C:\Users\MyName\Documents\Programming>nuitka --standalone --recurse-all --output-dir=deploy-nui K0.py
And the output
__main__.py: can't open file 'K0.py'.
K0.py is a simple code that I programmed, contains the following
import string
from random import *
characters = string.ascii_letters + string.punctuation + string.digits
password = "".join(choice(characters) for x in range(randint(12, 16)))
print(password)
for this case, Nuitka requires admin privileges.
Related
You know how in Linux when you try some Sudo stuff it tells you to enter the password and, as you type, nothing is shown in the terminal window (the password is not shown)?
Is there a way to do that in Python? I'm working on a script that requires so sensitive info and would like for it to be hidden when I'm typing it.
In other words, I want to get the password from the user without showing the password.
Use getpass.getpass():
from getpass import getpass
password = getpass()
An optional prompt can be passed as parameter; the default is "Password: ".
Note that this function requires a proper terminal, so it can turn off echoing of typed characters – see “GetPassWarning: Can not control echo on the terminal” when running from IDLE for further details.
import getpass
pswd = getpass.getpass('Password:')
getpass works on Linux, Windows, and Mac.
This code will print an asterisk instead of every letter.
import sys
import msvcrt
passwor = ''
while True:
x = msvcrt.getch()
if x == '\r':
break
sys.stdout.write('*')
passwor +=x
print '\n'+passwor
Updating on the answer of #Ahmed ALaa
# import msvcrt
import getch
def getPass():
passwor = ''
while True:
x = getch.getch()
# x = msvcrt.getch().decode("utf-8")
if x == '\r' or x == '\n':
break
print('*', end='', flush=True)
passwor +=x
return passwor
print("\nout=", getPass())
msvcrt us only for windows, but getch from PyPI should work for both (I only tested with linux).
You can also comment/uncomment the two lines to make it work for windows.
You can also use the pwinput module which works on both Windows and Linux.
It replaces the char with '*' (by default) and backspace works.
import pwinput
password = pwinput.pwinput(prompt='Password: ')
You can, optionally, pass a different mask character as well.
import pwinput
password = pwinput.pwinput(prompt='Password: ', mask='')
See the pwinput documentation for more information.
Here is my code based off the code offered by #Ahmed ALaa
Features:
Works for passwords up to 64 characters
Accepts backspace input
Outputs * character (DEC: 42 ; HEX: 0x2A) instead of the input character
Demerits:
Works on Windows only
The function secure_password_input() returns the password as a string when called. It accepts a Password Prompt string, which will be displayed to the user to type the password
def secure_password_input(prompt=''):
p_s = ''
proxy_string = [' '] * 64
while True:
sys.stdout.write('\x0D' + prompt + ''.join(proxy_string))
c = msvcrt.getch()
if c == b'\r':
break
elif c == b'\x08':
p_s = p_s[:-1]
proxy_string[len(p_s)] = " "
else:
proxy_string[len(p_s)] = "*"
p_s += c.decode()
sys.stdout.write('\n')
return p_s
You know how in Linux when you try some Sudo stuff it tells you to enter the password and, as you type, nothing is shown in the terminal window (the password is not shown)?
Is there a way to do that in Python? I'm working on a script that requires so sensitive info and would like for it to be hidden when I'm typing it.
In other words, I want to get the password from the user without showing the password.
Use getpass.getpass():
from getpass import getpass
password = getpass()
An optional prompt can be passed as parameter; the default is "Password: ".
Note that this function requires a proper terminal, so it can turn off echoing of typed characters – see “GetPassWarning: Can not control echo on the terminal” when running from IDLE for further details.
import getpass
pswd = getpass.getpass('Password:')
getpass works on Linux, Windows, and Mac.
This code will print an asterisk instead of every letter.
import sys
import msvcrt
passwor = ''
while True:
x = msvcrt.getch()
if x == '\r':
break
sys.stdout.write('*')
passwor +=x
print '\n'+passwor
Updating on the answer of #Ahmed ALaa
# import msvcrt
import getch
def getPass():
passwor = ''
while True:
x = getch.getch()
# x = msvcrt.getch().decode("utf-8")
if x == '\r' or x == '\n':
break
print('*', end='', flush=True)
passwor +=x
return passwor
print("\nout=", getPass())
msvcrt us only for windows, but getch from PyPI should work for both (I only tested with linux).
You can also comment/uncomment the two lines to make it work for windows.
You can also use the pwinput module which works on both Windows and Linux.
It replaces the char with '*' (by default) and backspace works.
import pwinput
password = pwinput.pwinput(prompt='Password: ')
You can, optionally, pass a different mask character as well.
import pwinput
password = pwinput.pwinput(prompt='Password: ', mask='')
See the pwinput documentation for more information.
Here is my code based off the code offered by #Ahmed ALaa
Features:
Works for passwords up to 64 characters
Accepts backspace input
Outputs * character (DEC: 42 ; HEX: 0x2A) instead of the input character
Demerits:
Works on Windows only
The function secure_password_input() returns the password as a string when called. It accepts a Password Prompt string, which will be displayed to the user to type the password
def secure_password_input(prompt=''):
p_s = ''
proxy_string = [' '] * 64
while True:
sys.stdout.write('\x0D' + prompt + ''.join(proxy_string))
c = msvcrt.getch()
if c == b'\r':
break
elif c == b'\x08':
p_s = p_s[:-1]
proxy_string[len(p_s)] = " "
else:
proxy_string[len(p_s)] = "*"
p_s += c.decode()
sys.stdout.write('\n')
return p_s
I am trying to generate encrypted password strings, similar to /etc/shadow in Linux. For some reason the output I am getting is different. Any ideas what am I missing and is one has longer than the other (not counting the salt portion)?
#!/usr/bin/python
import crypt
alg = 6 # SHA512
salt = 'vb1tLY1qiY'
word = 'password'
insalt = '${}${}$'.format(alg, salt)
cryptWord = crypt.crypt(word, insalt)
print cryptWord
The output is: $6FMi11BJFsAc
If I generate this in Linux like this:
mkpasswd --method=sha-512 --salt=vb1tLY1qiY password
The output is: $6$vb1tLY1qiY$WFHTa6CRShEuKg63vuPTYOVRK1oQiM6johIEs2JslF1904VhEdSXlHje74eB4uLXHrKNyZ4bPjSlWpZD6qIo71
I was able to use passlib. It doesn't come installed as part of python (at least on OS X) but, you can install it via pip.
sudo easy_install pip
pip install passlib
python -c "from passlib.hash import sha512_crypt; import getpass,string,random; print sha512_crypt.using(salt=''.join([random.choice(string.ascii_letters + string.digits) for _ in range(16)]),rounds=5000).hash(getpass.getpass())"
https://gist.github.com/hbeatty/25db5847e7068335681db88248d0deaf
You know how in Linux when you try some Sudo stuff it tells you to enter the password and, as you type, nothing is shown in the terminal window (the password is not shown)?
Is there a way to do that in Python? I'm working on a script that requires so sensitive info and would like for it to be hidden when I'm typing it.
In other words, I want to get the password from the user without showing the password.
Use getpass.getpass():
from getpass import getpass
password = getpass()
An optional prompt can be passed as parameter; the default is "Password: ".
Note that this function requires a proper terminal, so it can turn off echoing of typed characters – see “GetPassWarning: Can not control echo on the terminal” when running from IDLE for further details.
import getpass
pswd = getpass.getpass('Password:')
getpass works on Linux, Windows, and Mac.
This code will print an asterisk instead of every letter.
import sys
import msvcrt
passwor = ''
while True:
x = msvcrt.getch()
if x == '\r':
break
sys.stdout.write('*')
passwor +=x
print '\n'+passwor
Updating on the answer of #Ahmed ALaa
# import msvcrt
import getch
def getPass():
passwor = ''
while True:
x = getch.getch()
# x = msvcrt.getch().decode("utf-8")
if x == '\r' or x == '\n':
break
print('*', end='', flush=True)
passwor +=x
return passwor
print("\nout=", getPass())
msvcrt us only for windows, but getch from PyPI should work for both (I only tested with linux).
You can also comment/uncomment the two lines to make it work for windows.
You can also use the pwinput module which works on both Windows and Linux.
It replaces the char with '*' (by default) and backspace works.
import pwinput
password = pwinput.pwinput(prompt='Password: ')
You can, optionally, pass a different mask character as well.
import pwinput
password = pwinput.pwinput(prompt='Password: ', mask='')
See the pwinput documentation for more information.
Here is my code based off the code offered by #Ahmed ALaa
Features:
Works for passwords up to 64 characters
Accepts backspace input
Outputs * character (DEC: 42 ; HEX: 0x2A) instead of the input character
Demerits:
Works on Windows only
The function secure_password_input() returns the password as a string when called. It accepts a Password Prompt string, which will be displayed to the user to type the password
def secure_password_input(prompt=''):
p_s = ''
proxy_string = [' '] * 64
while True:
sys.stdout.write('\x0D' + prompt + ''.join(proxy_string))
c = msvcrt.getch()
if c == b'\r':
break
elif c == b'\x08':
p_s = p_s[:-1]
proxy_string[len(p_s)] = " "
else:
proxy_string[len(p_s)] = "*"
p_s += c.decode()
sys.stdout.write('\n')
return p_s
I made a small script in sublime that will extract commands from a json file that is on the user's computer and then it will open the terminal and run the settings/command. This works, except that it doesn't really open up the terminal. It only runs the command (and it works, as in my case it will run gcc to compile a simple C file), and pipes to STDOUT without opening up the terminal.
import json
import subprocess
import sublime_plugin
class CompilerCommand(sublime_plugin.TextCommand):
def get_dir(self, fullpath):
path = fullpath.split("\\")
path.pop()
path = "\\".join(path)
return path
def get_settings(self, path):
_settings_path = path + "\\compiler_settings.json"
return json.loads(open(_settings_path).read())
def run(self, edit):
_path = self.get_dir(self.view.file_name())
_settings = self.get_settings(_path)
_driver = _path.split("\\")[0]
_command = _driver + " && cd " + _path + " && " + _settings["compile"] + " && " + _settings["exec"]
proc = subprocess.Popen(_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
I'm not sure if using subprocess.Popen is the right way to go about it as I'm new to Python.
So to re-iterate; I want it to open up the terminal, run the command, and have the terminal stay open until the user presses ENTER or something. I'm running Windows 7 and Python 3, if that matters.
subprocess.Popen simply creates a subprocess with the given command. It is in no way related to opening a terminal window or any other windows for that matter.
You'll have to look into your platform specific UI automation solutions in order to achieve what you want. Or see if maybe the Sublime plugins mechanism can already do that.
NOTES:
Also, you should be using os.path.join/os.path.split/os.path.sep etc for your path operations—Sublime also runs on OS X for example, and OS X does not use backslashes. Also, file handles need to be closed, so use:
with open(...) as f:
return json.load(f) # also not that there is no nead to f.read()+json.loads()
# if you can just json.load() on the file handle
Furthermore, strings should usually be built using string interpolation:
_command = "{} && cd {} && {} && {}".format(_driver, _path, _settings["compile"], _settings["exec"])
...and, you should not be prefixing your local variables with _—it doesn't look nice and serves no purpose in Python either; and while we're at it, I might as well use the chance to recommend you to read PEP8: http://www.python.org/dev/peps/pep-0008/.