Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
change application password hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
zegenie committed Sep 19, 2018
1 parent 53405ae commit 6cbb083
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 71 deletions.
14 changes: 11 additions & 3 deletions core/entities/ApplicationPassword.php
Expand Up @@ -68,7 +68,7 @@ class ApplicationPassword extends IdentifiableScoped
*/
public static function createToken($application_password)
{
return hash("sha256", $application_password);
return password_hash($application_password, PASSWORD_DEFAULT);
}

protected function _preSave($is_new)
Expand Down Expand Up @@ -128,8 +128,7 @@ public function getPassword()
*/
public function setPassword($newpassword)
{
$token = self::createToken($newpassword);
$this->_password = \thebuggenie\core\entities\User::hashPassword($token, $this->getUser()->getSalt());
$this->_password = password_hash($newpassword, PASSWORD_DEFAULT);
}

public function getCreatedAt()
Expand Down Expand Up @@ -157,6 +156,15 @@ public function setLastUsedAt($last_used_at)
$this->_last_used_at = $last_used_at;
}

public function verify()
{
$password = User::createPassword(20);
$this->_password = password_hash($password, PASSWORD_DEFAULT);
$this->useOnce();

return $password;
}

public function useOnce()
{
$this->_last_used_at = time();
Expand Down
16 changes: 9 additions & 7 deletions core/entities/Issuetype.php
Expand Up @@ -240,14 +240,16 @@ public function isAssociatedWithAnySchemes()

public function toJSON($detailed = true)
{
return array(
'id' => $this->getID(),
'key' => $this->getKey(),
'name' => $this->getName(),
'icon' => $this->getIcon(),
'is_task' => $this->isTask(),
'description' => $this->getDescription()
$json = array(
'id' => $this->getID(),
'key' => $this->getKey(),
'name' => $this->getName(),
'icon' => $this->getIcon(),
'is_task' => $this->isTask(),
'description' => $this->getDescription()
);

return $json;
}

}
Expand Down
83 changes: 39 additions & 44 deletions core/entities/Project.php
Expand Up @@ -3367,54 +3367,49 @@ public function preloadValues()

public function toJSON($detailed = true)
{
$jsonArray = array(
'id' => $this->getID(),
'key' => $this->getKey(),
'name' => $this->getName(),
'href' => framework\Context::getRouting()->generate('project_dashboard', array('project_key' => $this->getKey())),
'deleted' => $this->isDeleted(),
'archived' => $this->isArchived()
);
if($detailed) {
$jsonArray['icon_large'] = $this->getLargeIconName();
$jsonArray['icon_small'] = $this->getSmallIconName();
$jsonArray['description'] = $this->getDescription();
$jsonArray['url_documentation'] = $this->getDocumentationURL();
$jsonArray['url_homepage'] = $this->getHomepage();
$jsonArray['url_wiki'] = $this->getWikiURL();

$jsonArray['prefix_used'] = $this->doesUsePrefix();
$jsonArray['prefix'] = $this->getPrefix();

$jsonArray['workflow_scheme'] = $this->hasWorkflowScheme() ? $this->getWorkflowScheme()->toJSON() : null;
$jsonArray['issuetype_scheme'] = $this->getIssuetypeScheme()->toJSON();

$jsonArray['builds_enabled'] = $this->isBuildsEnabled();
$jsonArray['editions_enabled'] = $this->isEditionsEnabled();
$jsonArray['components_enabled'] = $this->isComponentsEnabled();
$jsonArray['allow_freelancing'] = $this->canChangeIssuesWithoutWorkingOnThem();

$jsonArray['released'] = $this->isReleased();
$jsonArray['release_date'] = $this->getReleaseDate();

$jsonArray['frontpage_shown'] = $this->isShownInFrontpageSummary();
$jsonArray['frontpage_summary_type'] = $this->getFrontpageSummaryType();
$jsonArray['frontpage_milestones_visible'] = $this->isMilestonesVisibleInFrontpageSummary();
$jsonArray['frontpage_issuetypes_visible'] = $this->isIssuetypesVisibleInFrontpageSummary();
$jsonArray['frontpage_issuelist_visible'] = $this->isIssuelistVisibleInFrontpageSummary();

$jsonArray['parent'] = $this->hasParent() ? $this->getParent()->toJSON() : null;
$jsonArray['leader'] = $this->hasLeader() ? $this->getLeader()->toJSON() : null;
$jsonArray['owner'] = $this->hasOwner() ? $this->getOwner()->toJSON() : null;
$jsonArray['qa_responsible'] = $this->hasQaResponsible() ? $this->getQaResponsible()->toJSON() : null;
$jsonArray['client'] = $this->hasClient() ? $this->getClient()->toJSON() : null;

$jsonArray = [
'id' => $this->getID(),
'key' => $this->getKey(),
'name' => $this->getName(),
'href' => framework\Context::getRouting()->generate('project_dashboard', ['project_key' => $this->getKey()]),
'deleted' => $this->isDeleted(),
'archived' => $this->isArchived(),
'icon_large' => $this->getLargeIconName(),
'icon_small' => $this->getSmallIconName(),
'description' => $this->getDescription(),
'url_documentation' => $this->getDocumentationURL(),
'url_homepage' => $this->getHomepage(),
'url_wiki' => $this->getWikiURL(),
'prefix_used' => $this->doesUsePrefix(),
'prefix' => $this->getPrefix(),
'parent' => $this->hasParent() ? $this->getParent()->toJSON() : null,
'leader' => $this->hasLeader() ? $this->getLeader()->toJSON(false) : null,
'owner' => $this->hasOwner() ? $this->getOwner()->toJSON(false) : null,
'qa_responsible' => $this->hasQaResponsible() ? $this->getQaResponsible()->toJSON(false) : null,
'client' => $this->hasClient() ? $this->getClient()->toJSON(false) : null,
'released' => $this->isReleased(),
'release_date' => $this->getReleaseDate(),
'settings' => [
'workflow_scheme' => $this->hasWorkflowScheme() ? $this->getWorkflowScheme()->toJSON() : null,
'issuetype_scheme' => $this->getIssuetypeScheme()->toJSON(),
'builds_enabled' => $this->isBuildsEnabled(),
'editions_enabled' => $this->isEditionsEnabled(),
'components_enabled' => $this->isComponentsEnabled(),
'allow_freelancing' => $this->canChangeIssuesWithoutWorkingOnThem(),
'frontpage_shown' => $this->isShownInFrontpageSummary(),
'frontpage_summary_type' => $this->getFrontpageSummaryType(),
'frontpage_milestones_visible' => $this->isMilestonesVisibleInFrontpageSummary(),
'frontpage_issuetypes_visible' => $this->isIssuetypesVisibleInFrontpageSummary(),
'frontpage_issuelist_visible' => $this->isIssuelistVisibleInFrontpageSummary(),
]
];

if ($detailed) {
$jsonArray['issues_count'] = $this->countAllIssues();
$jsonArray['issues_count_open'] = $this->countAllOpenIssues();
$jsonArray['issues_count_closed'] = $this->countAllClosedIssues();
$jsonArray['issues_percent_closed'] = $this->getClosedPercentageForAllIssues();

}

return $jsonArray;
}

Expand Down
2 changes: 1 addition & 1 deletion core/entities/Team.php
Expand Up @@ -21,7 +21,7 @@
* @package thebuggenie
* @subpackage main
*
* @static @method tables\Teams getB2DBTable()
* @method static tables\Teams getB2DBTable()
*
* @Table(name="\thebuggenie\core\entities\tables\Teams")
*/
Expand Down
2 changes: 1 addition & 1 deletion core/entities/tables/Files.php
Expand Up @@ -23,7 +23,7 @@
* @package thebuggenie
* @subpackage tables
*
* @static @method Files getTable()
* @method static Files getTable()
*
* @Table(name="files")
* @Entity(class="\thebuggenie\core\entities\File")
Expand Down
2 changes: 1 addition & 1 deletion core/entities/tables/IssueRelations.php
Expand Up @@ -19,7 +19,7 @@
/**
* Issue relations table
*
* @static @method IssueRelations getTable() Retrieves an instance of this table
* @method static IssueRelations getTable() Retrieves an instance of this table
* @package thebuggenie
* @subpackage tables
*
Expand Down
2 changes: 1 addition & 1 deletion core/entities/tables/Issues.php
Expand Up @@ -23,7 +23,7 @@
* @package thebuggenie
* @subpackage tables
*
* @static @method Issues getTable() Retrieves an instance of this table
* @method static Issues getTable() Retrieves an instance of this table
* @method \thebuggenie\core\entities\Issue selectById(integer $id, Criteria $crit = null, $join = 'all') Retrieves an issue
*
* @Entity(class="\thebuggenie\core\entities\Issue")
Expand Down
2 changes: 1 addition & 1 deletion core/entities/tables/Milestones.php
Expand Up @@ -23,7 +23,7 @@
* @package thebuggenie
* @subpackage tables
*
* @static @method Milestones getTable() Retrieves an instance of this table
* @method static Milestones getTable() Retrieves an instance of this table
* @method \thebuggenie\core\entities\Milestone selectById(integer $id) Retrieves a milestone
*
* @Table(name="milestones")
Expand Down
2 changes: 1 addition & 1 deletion core/entities/tables/Modules.php
Expand Up @@ -20,7 +20,7 @@
* @package thebuggenie
* @subpackage tables
*
* @static @method Modules getTable() Retrieves an instance of this table
* @method static Modules getTable() Retrieves an instance of this table
* @method \thebuggenie\core\entities\Module selectById(integer $id) Retrieves a module
*
* @Table(name="modules")
Expand Down
9 changes: 5 additions & 4 deletions core/entities/tables/ProjectAssignedUsers.php
Expand Up @@ -18,6 +18,7 @@
/**
* Project assigned users table
*
* @method static ProjectAssignedUsers getTable()
* @package thebuggenie
* @subpackage tables
*
Expand Down Expand Up @@ -92,7 +93,7 @@ public function getUserByProjectIDUserIDRoleID($project_id, $user_id, $role_id)
{
$uid = $row['uid'];
if (!array_key_exists($uid, $users))
$users[$uid] = new \thebuggenie\core\entities\User($uid);
$users[$uid] = Users::getTable()->selectById($uid);
// Only one user is needed since only one can be inserted in method "addUserToProject".
break;
}
Expand All @@ -115,7 +116,7 @@ public function getProjectsByUserID($user_id)
{
$pid = $row['pid'];
if (!array_key_exists($pid, $projects))
$projects[$pid] = new Project($pid);
$projects[$pid] = Projects::getTable()->selectById($pid);
}
}

Expand All @@ -141,7 +142,7 @@ public function getRolesForProject($project_id)
{
while ($row = $res->getNextRow())
{
$roles[$row->get(self::USER_ID)][] = new \thebuggenie\core\entities\Role($row->get(self::ROLE_ID));
$roles[$row->get(self::USER_ID)][] = ListTypes::getTable()->selectById($row->get(self::ROLE_ID));
}
}

Expand All @@ -162,7 +163,7 @@ public function getUsersByRoleID($role_id)
{
$uid = $row['uid'];
if (!array_key_exists($uid, $users))
$users[$uid] = new \thebuggenie\core\entities\User($uid);
$users[$uid] = Users::getTable()->selectById($uid);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/entities/tables/Projects.php
Expand Up @@ -23,7 +23,7 @@
* @package thebuggenie
* @subpackage tables
*
* @static @method Projects getTable() Retrieves an instance of this table
* @method static Projects getTable() Retrieves an instance of this table
* @method \thebuggenie\core\entities\Project selectById(integer $id) Retrieves a project
*
* @Table(name="projects")
Expand Down
2 changes: 1 addition & 1 deletion core/entities/tables/WorkflowTransitionValidationRules.php
Expand Up @@ -23,7 +23,7 @@
* @package thebuggenie
* @subpackage tables
*
* @static @method WorkflowTransitionValidationRules getTable() Return an instance of this table
* @method static WorkflowTransitionValidationRules getTable() Return an instance of this table
* @method \thebuggenie\core\entities\WorkflowTransitionValidationRule selectById() Return a WorkflowTransitionValidationRule object
*
* @Table(name="workflow_transition_validation_rules")
Expand Down
2 changes: 1 addition & 1 deletion core/framework/Routing.php
Expand Up @@ -338,7 +338,7 @@ protected function loadModuleAnnotationRoutes($classname, $module)
$actionName = substr($method->name, 3);
$action = $controller . '::' . $actionName;
$name = $route_name_prefix . (($route_annotation->hasProperty('name')) ? $route_annotation->getProperty('name') : strtolower($actionName));
$route = $route_url_prefix . $route_annotation->getProperty('url');
$route = rtrim($route_url_prefix . $route_annotation->getProperty('url'), '/');
$options['csrf_enabled'] = $annotationset->hasAnnotation('CsrfProtected');
$options['anonymous_route'] = $annotationset->hasAnnotation('AnonymousRoute');
$options['authentication_method'] = ($annotationset->hasAnnotation('AuthenticationMethod')) ? $annotationset->getAnnotation('AuthenticationMethod') : '';
Expand Down

0 comments on commit 6cbb083

Please sign in to comment.