I am getting error while encrypting the password using Python. I am explaining the error below.
Error:
Traceback (most recent call last):
File "password.py", line 60, in <module>
hashed_password = hashlib.sha512(sword + salt).hexdigest()
TypeError: cannot concatenate 'str' and 'list' objects
My code is given below.
import hashlib
value = "2Y7xk5vrs5DeCcSdinRVKQ=="
salt = value.split()
sword = "subhra1234"
hashed_password = hashlib.sha512(sword + salt).hexdigest()
print(hashed_password)
Here I need to use own salt value and trying to encrypting the password. Please help to resolve this error.
Like #MosesKoledoye said, you don't need to call split on the salt:
import hashlib
salt = "2Y7xk5vrs5DeCcSdinRVKQ=="
sword = "subhra1234"
hashed_password = hashlib.sha512(sword + salt).hexdigest()
print(hashed_password)
Related
I wanted to do an Email writer. I saw a tutorial and this came out:
import smtplib
import os
user = os.getenv("SMTP_USER")
pwd = os.getenv("SMTP_PWO")
mail_text = "Hallo, \n\ndas ist ein Test!\n\n"
subject = "Python Mail"
MAIL_FROM = "x.muelfellner#outlook.de"
RCPT_TO = input("Empfänger: ")
DATA = "From:%s\nTo:%s\nSubject:%s\n\n%" \
(MAIL_FROM,RCPT_TO,subject,mail_text)
server = smtplib.SMTP("secure.emailsrvr.com:587")
server.starttls()
server.login(user,pwd)
server.sendmail(MAIL_FROM,RCPT_TO,DATA)
server.quit()
But when I'm running the code there's an Error. Here:
Traceback (most recent call last):
File "/home/pi/Bookshelf/Pyton/SendEmail.py", line 12, in <module>
(MAIL_FROM,RCPT_TO,subject,mail_text)
TypeError: 'str' object is not callable
I don't know what i have to change! Can someone help me?
Your problem isn't related to smtplib; it's just a syntax error.
You're inadvertently trying to call a string (I removed the \ continuation):
DATA = "From:%s\nTo:%s\nSubject:%s\n\n%"(MAIL_FROM,RCPT_TO,subject,mail_text)
It should be
DATA = "From:%s\nTo:%s\nSubject:%s\n\n%s" % (MAIL_FROM,RCPT_TO,subject,mail_text)
to format a string.
I'm in the middle of taking a basic AP Computer Science class on Python, I am working on a project that is able to encrypt a password with salt and then decrypt it using the key. I experienced the error below, which was shown when I attempted to start the decryption process of a password using various cryptography libraries
Error I recieved:
Traceback (most recent call last):
File "main.py", line 104, in <module>
everything()
File "main.py", line 96, in everything
f = Fernet(passCrypt) # Value of an actual key is given.
UnboundLocalError: local variable 'passCrypt' referenced before assignment
Encryption Process
password = input("Enter your password: ")
pass_Encoded = password.encode()
salt = base64.urlsafe_b64encode(os.urandom(16))
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
salt=salt,
iterations=100000,
backend=default_backend()
)
key = base64.urlsafe_b64encode(kdf.derive(pass_Encoded))
clearConsole()
print("The key is: ", key)
x = Fernet(key)
passCrypt = x.encrypt(pass_Encoded)
print("The encrypted pass is: ", passCrypt)
Decryption Process
else:
x = Fernet(passCrypt) # Value of an actual key is given.
decrypted_data = x.decrypt(passCrypt)
print("After decryption : ", decrypted_data.decode())
Ignore the "else:" it's just because I have a selection between 1 and 2 to register a key and decrypt it. I'm sure I'm doing this completely incorrectly especially with the salt so some assistance would be very helpful. Thanks
import smtplib
smtpserver = s.connect("mail.btinternet.com", 465)
SMTP.helo("mail.btinternet.com")
SMTP.ehlo("mail.btinternet.com")
file = open("Combo.txt", "r")
for line in file:
x = line.split(":")
user = x[0]
password = x[1]
s.login(user, password)
print("[+] Password Found: %s" % password)
if smtplib.SMTPAuthenticationError:
print("Incorrect")
Here's my code. It checks a list of email/password combinations from a file to see if it is on a specific server (in my case BT).
But I am having trouble with the library names, I am not sure what to use. I checked on python docs but it wasn't clear enough, if someone can tell me as to what is incorrect I would deeply appreciate it.
Error received.
This will also give me errors for the other incorrect library names
Traceback (most recent call last):
File "main.py", line 3, in <module>
smtpserver = s.connect("mail.btinternet.com", 465)
NameError: name 's' is not defined
exited with non-zero status
For your problem I think the reason why as to your libraries are not working properly is because you're calling your imported library inconsistently:
e.g. sometimes you type 's.xxxxx', sometimes you type 'SMTPlib.xxxxx' for your module attributes, you should import smtplib as 's'.
So what does this is it stores the library in a short form named 's', so whenever you call a module or use a function from the library, you don't have to type the full '.smtplib' but instead just type a '.s' extension behind the specific function:
import smtplib as s
smtpserver = s.connect("mail.btinternet.com", 465)
s.helo("mail.btinternet.com")
s.ehlo("mail.btinternet.com")
file = open("Combo.txt", "r")
for line in file:
x = line.split(":")
user = x[0]
password = x[1]
s.login(user, password)
print("[+] Password Found: %s" % password)
if s.SMTPAuthenticationError:
print("Incorrect")
Should fix your problems now. remember to call functions from the specific library name in a consistent manner ('s').
I am getting error while hashing the pain text password using Bcrypt in Python. I am providing the error below.
Traceback (most recent call last):
File "hash.py", line 3, in <module>
hashed = hashpw(plaintext_password, gensalt(log_rounds=13))
TypeError: gensalt() got an unexpected keyword argument 'log_rounds'
My code is given below.
from bcrypt import hashpw, gensalt
plaintext_password = 'subhra123#'
hashed = hashpw(plaintext_password, gensalt(log_rounds=13))
print hashed
Here I need to hash my password.
Your error comes from log_rounds, you simply should just use the number. Here is an example:
hashed = hashpw(plaintext_password, gensalt(13))
From the official docs:
Adjustable Work Factor
One of bcrypt’s features is an adjustable logarithmic work factor. To adjust the work factor merely pass the desired number of rounds to bcrypt.gensalt(rounds=12) which defaults to 12):
Working demo:
import bcrypt
password = b"super secret password"
# Hash a password for the first time, with a certain number of rounds
hashed = bcrypt.hashpw(password, bcrypt.gensalt(14))
# Check that a unhashed password matches one that has previously been
# hashed
if bcrypt.hashpw(password, hashed) == hashed:
print("It Matches!")
else:
print("It Does not Match :(")
Here is a link to the docs, where it specifies how to work with this.
Hope this helps!
I thing you want to use gensalt(13) or gensalt(rounds=13) instead of gensalt(log_rounds=13).
So I'm working on a Python script to extract text from an email and following these instructions to do so. This is the script thus far:
import imapclient
import pprint
import pyzmail
mymail = "my#email.com"
password = input("Password: ")
imapObj = imapclient.IMAPClient('imap.gmail.com' , ssl=True)
imapObj.login(mymail , password)
imapObj.select_folder('INBOX', readonly=False)
UIDs = imapObj.search(['SUBJECT Testing'])
rawMessages = imapObj.fetch([5484], ['BODY[]'])
message = pyzmail.PyzMessage.factory(rawMessages[5484]['BODY[]'])
However I'm getting this error:
message = pyzmail.PyzMessage.factory(rawMessages[5484]['BODY[]'])
KeyError: 5484
5484 being the ID for the email that the search function finds. I've also tried putting UIDs in instead of 5484, but that doesn't work either. Thanks in advance!
Thank you #Madalin Stroe .
I use python3.6.2 and pyzmail1.0.3 on Win10.
When I run
message = pyzmail.PyzMessage.factory(rawMessages[4]['BODY[]'])
The ERR shows like this:
Traceback (most recent call last):
File "PATH/TO/mySinaEmail.py", line 42, in <module>
message = pyzmail.PyzMessage.factory(rawMessages[4]['BODY[]'])
KeyError: 'BODY[]'
When I modified this to message = pyzmail.PyzMessage.factory(rawMessages[4][b'BODY[]']), it run well.
Try replacing ['BODY[]'] with [b'BODY[]']