xref: /freebsd/usr.sbin/pw/tests/crypt.c (revision b3e76948)
17c46e6efSAlan Somers /*-
27c46e6efSAlan Somers  * Copyright (c) 2016 Spectra Logic Corporation
37c46e6efSAlan Somers  * All rights reserved.
47c46e6efSAlan Somers  *
57c46e6efSAlan Somers  * Redistribution and use in source and binary forms, with or without
67c46e6efSAlan Somers  * modification, are permitted provided that the following conditions
77c46e6efSAlan Somers  * are met:
87c46e6efSAlan Somers  * 1. Redistributions of source code must retain the above copyright
97c46e6efSAlan Somers  *    notice, this list of conditions and the following disclaimer.
107c46e6efSAlan Somers  * 2. Redistributions in binary form must reproduce the above copyright
117c46e6efSAlan Somers  *    notice, this list of conditions and the following disclaimer in the
127c46e6efSAlan Somers  *    documentation and/or other materials provided with the distribution.
137c46e6efSAlan Somers  *
147c46e6efSAlan Somers  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
157c46e6efSAlan Somers  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
167c46e6efSAlan Somers  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
177c46e6efSAlan Somers  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
187c46e6efSAlan Somers  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
197c46e6efSAlan Somers  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
207c46e6efSAlan Somers  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
217c46e6efSAlan Somers  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
227c46e6efSAlan Somers  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
237c46e6efSAlan Somers  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
247c46e6efSAlan Somers  * SUCH DAMAGE.
257c46e6efSAlan Somers  */
267c46e6efSAlan Somers 
277c46e6efSAlan Somers #include <err.h>
287c46e6efSAlan Somers #include <stdio.h>
297c46e6efSAlan Somers #include <unistd.h>
307c46e6efSAlan Somers 
main(int argc,char ** argv)317c46e6efSAlan Somers int main(int argc, char** argv)
327c46e6efSAlan Somers {
337c46e6efSAlan Somers 	char *salt, *pass, *hash;
347c46e6efSAlan Somers 
357c46e6efSAlan Somers 	if (argc < 3)
367c46e6efSAlan Somers 		errx(1, "Usage: crypt <salt> <password>");
377c46e6efSAlan Somers 	salt = argv[1];
387c46e6efSAlan Somers 	pass = argv[2];
397c46e6efSAlan Somers 
407c46e6efSAlan Somers 	hash = crypt(pass, salt);
417c46e6efSAlan Somers 	printf("%s", hash);
427c46e6efSAlan Somers 	return (hash == NULL ? 1 : 0);
437c46e6efSAlan Somers }
44