def cookie_login(self): if api.sysparam.get_bool('DISABLE_COOKIES'): log.info("Cookies disable by parameter") return cookie_file = get_utility(ICookieFile) try: username, password = cookie_file.get() except CookieError: log.info("Not using cookie based login") return def is_md5(password): # This breaks for passwords that are 32 characters long, # uses only digits and lowercase a-f, pretty unlikely as # real-world password if len(password) != 32: return False for c in '1234567890abcdef': password = password.replace(c, '') return password == '' # Migrate old passwords to md5 hashes. if not is_md5(password): password = LoginUser.hash(password) cookie_file.store(username, password) try: user = self._check_user(username, password) except (LoginError, UserProfileError, DatabaseError) as e: log.info("Cookie login failed: %r" % e) return log.info("Logging in using cookie credentials") return user
def on_confirm(self): password = LoginUser.hash(self.model.password) current_branch = api.get_current_branch(self.store) try: self.retval = LoginUser.authenticate(self.store, self.model.username, password, current_branch) except LoginError as e: self.retval = None warning(str(e))
def _do_login(self): username = unicode(self.username.get_text().strip()) password = unicode(self.password.get_text().strip()) password = LoginUser.hash(password) self.retval = username, password self.set_field_sensitivity(False) self.notification_label.set_color('black') msg = _(" Authenticating user...") self.notification_label.set_text(msg) while gtk.events_pending(): gtk.main_iteration() gtk.main_quit() self.set_field_sensitivity(True)
def _do_login(self): username = str(self.username.get_text().strip()) password = str(self.password.get_text().strip()) password = LoginUser.hash(password) self.retval = username, password self.set_field_sensitivity(False) self.notification_label.set_color('black') msg = _(" Authenticating user...") self.notification_label.set_text(msg) while Gtk.events_pending(): Gtk.main_iteration() Gtk.main_quit() self.set_field_sensitivity(True)
def validate_user(self): """ Checks if an user can log in or not. :returns: a user object """ # If there is only one user, and that user is admin with a blank # password, just log the user in store = api.get_default_store() if store.find(LoginUser).count() == 1: try: return self._check_user(u'admin', LoginUser.hash(u'')) except Exception: pass log.info("Showing login dialog") # Loop for logins retry = 0 retry_msg = None dialog = None while retry < RETRY_NUMBER: username = self._force_username password = None if not dialog: dialog = LoginDialog(_("Stoq - Access Control")) if self._force_username: dialog.force_username(username) ret = dialog.run(username, password, msg=retry_msg) # user cancelled (escaped) the login dialog if not ret: return # Use credentials if not (isinstance(ret, (tuple, list)) and len(ret) == 2): raise ValueError('Invalid return value, got %s' % str(ret)) username, password = ret if not username: retry_msg = _("specify an username") continue try: user = self._check_user(username, password) except (LoginError, UserProfileError) as e: # We don't hide the dialog here; it's kept open so the # next loop we just can call run() and display the error cookie = get_utility(ICookieFile, None) if cookie: cookie.clear() retry += 1 retry_msg = str(e) except DatabaseError as e: if dialog: dialog.destroy() self._abort(str(e)) else: log.info("Authenticated user %s" % username) self._force_username = None if dialog.remember.get_active(): get_utility(ICookieFile).store(user.username, user.pw_hash) if dialog: dialog.destroy() return user if dialog: dialog.destroy() raise LoginError(_("Depleted attempts of authentication"))