def checksum_sha256_buffer(buffer, offset=0, size=None): try: hash = sha256() except Exception: # fallback to Crypto SHA256 module hash = sha256.new() if size is None: hash.update(buffer) else: hash.update(buffer[offset:offset+size]) return hash
def checksum_sha256_buffer(buffer, offset=0, size=None): try: hash = sha256() except: # fallback to Crypto SHA256 module hash = sha256.new() if size is None: hash.update(buffer) else: hash.update(buffer[offset:offset+size]) return hash
def register(request): # if request.user.is_authenticated(): # logger.error('AUTH!') # # They already have an account; don't let them register again # return render_to_response('register.html', {'has_account': True}) if request.POST: form = NewConsommateursForm(request.POST) if form.is_valid: form.save() # Build the activation key for their account salt = sha.new(str(random.random())).hexdigest()[:5] activation_key = sha.new(salt+new_user.username).hexdigest() key_expires = datetime.datetime.today() + datetime.timedelta(2) # Create and save their profile new_profile = consommateurs( user=new_user, activation_key=activation_key, key_expires=key_expires) new_profile.save() # Send an email with the confirmation link email_subject = 'Your new example.com account confirmation' email_body = "Hello, %s, and thanks for signing up for an \ example.com account!\n\nTo activate your account, click this link within 48 \ hours:\n\nhttp://127.0.0.1:8000/consommateurs/confirm/%s" % (new_user.username,new_profile.activation_key) send_mail( email_subject, email_body, '*****@*****.**', [new_user.email] ) print(email_body) return render_to_response('register.html', {'created': True}) else: logger.error('GET!') errors = new_data = {} form = NewConsommateursForm() #forms.FormWrapper(manipulator, new_data, errors) return render_to_response('register.html', {'form': form})
def checksum_sha256_file(filename, offset=0, size=None): try: hash = sha256() except: # fallback to Crypto SHA256 module hash = sha256.new() with open(deunicodise(filename), 'rb') as f: if size is None: for chunk in iter(lambda: f.read(8192), b''): hash.update(chunk) else: f.seek(offset) size_left = size while size_left > 0: chunk = f.read(min(8192, size_left)) size_left -= len(chunk) hash.update(chunk) return hash
def checksum_sha256_file(filename, offset=0, size=None): try: hash = sha256() except: # fallback to Crypto SHA256 module hash = sha256.new() with open(deunicodise(filename),'rb') as f: if size is None: for chunk in iter(lambda: f.read(8192), b''): hash.update(chunk) else: f.seek(offset) size_left = size while size_left > 0: chunk = f.read(min(8192, size_left)) size_left -= len(chunk) hash.update(chunk) return hash