From owner-freebsd-questions@freebsd.org Thu Aug 23 10:28:11 2018 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A4CF810891D3 for ; Thu, 23 Aug 2018 10:28:11 +0000 (UTC) (envelope-from 482254ac@razorfever.net) Received: from pmta31.teksavvy.com (pmta31.teksavvy.com [76.10.157.38]) (using TLSv1.2 with cipher RC4-SHA (128/128 bits)) (Client CN "*.teksavvy.com", Issuer "DigiCert SHA2 High Assurance Server CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 487688C1B5 for ; Thu, 23 Aug 2018 10:28:10 +0000 (UTC) (envelope-from 482254ac@razorfever.net) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2FwFADyin5b/0StpUVbGQEBAQEBAQEBA?= =?us-ascii?q?QEBAQcBAQEBAYIWgTkpP2oShBiIDV+LRwFOAQEBBQGBCCkEMwGVbYF6C4RsAoM?= =?us-ascii?q?NIjQYAQIBAQEBAQECAgJpKEIMAYRqAQUjFR4zCxgCAhQMBgICOR4TCAEBgx6Bd?= =?us-ascii?q?Q2iUIEugz+BKYV3E3iJJIEHgRIngmuEamECgjKCVwKIBg2FQXOMVQgBAo9lHYE?= =?us-ascii?q?+hnUPJYVZkzMMgUE5gVIfXIMvgiMBF44zI4Y/hgIjgiYBAQ?= X-IPAS-Result: =?us-ascii?q?A2FwFADyin5b/0StpUVbGQEBAQEBAQEBAQEBAQcBAQEBAYI?= =?us-ascii?q?WgTkpP2oShBiIDV+LRwFOAQEBBQGBCCkEMwGVbYF6C4RsAoMNIjQYAQIBAQEBA?= =?us-ascii?q?QECAgJpKEIMAYRqAQUjFR4zCxgCAhQMBgICOR4TCAEBgx6BdQ2iUIEugz+BKYV?= =?us-ascii?q?3E3iJJIEHgRIngmuEamECgjKCVwKIBg2FQXOMVQgBAo9lHYE+hnUPJYVZkzMMg?= =?us-ascii?q?UE5gVIfXIMvgiMBF44zI4Y/hgIjgiYBAQ?= X-IronPort-AV: E=Sophos;i="5.53,278,1531800000"; d="scan'208";a="43909208" Received: from 69-165-173-68.dsl.teksavvy.com (HELO mail.razorfever.net) ([69.165.173.68]) by smtp.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Aug 2018 06:28:04 -0400 Received: from [127.0.0.1] (mail.razorfever.net [192.168.0.4]) by mail.razorfever.net (8.15.2/8.15.2) with ESMTP id w7NAS2Vm054778 for ; Thu, 23 Aug 2018 06:28:02 -0400 (EDT) (envelope-from 482254ac@razorfever.net) X-Authentication-Warning: mail.razorfever.net: Host mail.razorfever.net [192.168.0.4] claimed to be [127.0.0.1] Subject: Re: What hash to use To: freebsd-questions@freebsd.org References: From: "Derek (freebsd lists)" <482254ac@razorfever.net> Message-ID: <74a041fe-b00a-673e-c43f-b72aa04e5297@razorfever.net> Date: Thu, 23 Aug 2018 06:28:02 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.4 required=5.0 tests=ALL_TRUSTED, FROM_STARTS_WITH_NUMS,RP_MATCHES_RCVD autolearn=disabled version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on mail.razorfever.net X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Aug 2018 10:28:11 -0000 On 2018-08-23 05:16 AM, Olivier wrote: > I am using a tools that hashes the passwords in the form of > $2b$10$OQBll77HJqnOR.zqK2jx8ukE6m68Azc7nrsgRdcT6bVfERRmzFV4. > > What magic tool can I use in freeBSD to do the same hashing? > Try this (cdemo.c): #include #include #include int main(void) { struct crypt_data buf1; char *hash; /* * Generate a crypt for storage, using salt as the algorithm selection * and parameters. */ hash = crypt_r("Initial example password.", "$2b$10$22bytesofbase64charactersfromdevurandom", &buf1); if (hash == NULL) { printf("crypt_r (hash) failed.\n"); return (3); } printf("crypt_r (hash) result: %s\n", hash); return (0); } Then: cc -lcrypt -o cdemo cdemo.c ./cdemo This is okay for a one-off. You might wire stdin to read the salt, or for bonus points make your own salt generator. Additionally, it's likely not a good idea to read the password from the command-line (argv+argc). A file descriptor (e.g. stdin) of some kind would be better, as it will show up in shell history and the process table. Some languages, e.g. python, php, etc will have a library to do this for you as well. Derek